Category : django-models

i have option that allow user to change email in his profile but without confirm new email so when he enter new email i want activate email to save it in his profile , how to add confirm i am using UserCreationForm models.py : from django.db import models from django.contrib.auth.models import User from django.db.models.signals import ..

Read more

I have a problem, probably in my design. In my Django project I have a ‘Flow’ object with ‘event_reason’ field in it, Foreign key to ‘Event’ object, therefore I need to import Event object, (otherwise I get the error: Cannot create form field for ‘event_reason’ yet, because its related model ‘Event’ has not been loaded ..

Read more

I am creating E-Learning website and I want to show course content like playlist. For that I use foreign key in models. Here is the code of models.py class Subject(models.Model): subject_id = models.AutoField(primary_key=True) title = models.CharField(max_length=500) desc = models.CharField(max_length=800) slug = models.CharField(max_length=130) image = models.ImageField() timeStamp = models.DateTimeField(default=now) def __str__(self): return self.title class Videos(models.Model): sno ..

Read more

I am creating E-Learning website and I want to show course content like playlist. For that I use foreign key in models. Here is the code of models.py class Subject(models.Model): subject_id = models.AutoField(primary_key=True) title = models.CharField(max_length=500) desc = models.CharField(max_length=800) slug = models.CharField(max_length=130) image = models.ImageField() timeStamp = models.DateTimeField(default=now) def __str__(self): return self.title class Videos(models.Model): sno ..

Read more

I have MyModel: class MyModel(models.Model): ELEMENTS_CHOICES = Choices( (1, ‘element1’), (2, ‘element2’), (3, ‘element3’), (4, ‘element4’), (10, ‘element10’), (12, ‘element12’), ) elements = MultiSelectField( _(‘elements’), choices=ELEMENTS_CHOICES, blank=True, ) I have also some MyModel objects with elements values like below: obj1.elements = [‘1’, ‘2’, ‘3’, ’10’, ’12’] obj2.elements = [‘1’, ‘3’, ’10’, ’12’] obj3.elements = [‘1’, ..

Read more

def clientinfo(request): clientForm = ClientInfoForm(prefix="client") criminalForm = OCCForm(prefix="criminal") if request.method == ‘POST’: clientForm = ClientInfoForm(request.POST,prefix="client") criminalForm = OCCForm(request.POST,prefix="criminal") criminalForm[‘cust_id_id’] = clientForm[‘id’] if clientForm.is_valid() or criminalForm.is_valid(): clientForm.save() criminalForm.save() print("SUCCESSFUL SUBMISSION") return render(request, ‘submitted.html’) return render(request, ‘clientinfo.html’, {‘form’: clientForm, ‘occform’: OCCForm}) My criminalForm has a ForeignKey field cust_id and i need to set it to the auto-generated ..

Read more

I am building a BlogPost Webapp and I am stuck on an Error. When i try to check browser then it is keep showing tzinfo argument must be None or of a tzinfo subclass, not type ‘datetime.datetime’ models.py class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE,default=”,unique=True) full_name = models.CharField(max_length=100,default=”) time = models.DateTimeField(auto_now_add=True) @property def age(self): current_datetime = ..

Read more

I am using formsets to create a feedback page but I am not able to access foreign key table values in django template. I have this models below that are for a feedback system. Models.py class FeedbackForm(amdl.AagamBaseModel): feedback_form_id = models.AutoField(primary_key=True) subject_teacher = models.ForeignKey(MapMySchoolUserSubject, models.DO_NOTHING) feedback_form_date = models.DateField() feedback_form_status = models.BooleanField() class Meta: db_table = ‘feedback_form’ ..

Read more

Test case setUp() that first creates a user and the try’s to force authenticate the user but a wired error occurs… TypeError: force_authenticate() missing 1 required positional argument: ‘self’ class PrivateUserApiTest(TestCase): """ Test API that require authentication """ def setUp(self): self.user = create_user( email="[email protected]", password="testpass", name="testName" ) print(self.user) self.client = APIClient self.client.force_authenticate(user=self.user) # <– Source: ..

Read more