class Year(models.Model): year = models.IntegerField()
class Month(models.Model): MONTH_CHOICE = ( (1 , "Jan"), (2, 'Feb'), (3, 'March'), (4, 'April'), (5, 'May'), (6, 'June'), (7, 'July'), (8, 'Aug'), (9, 'Sept'), (10, 'Oct'), (11, 'Nov'), (12, 'Dec') ) month = models.PositiveSmallIntegerField(choices = MONTH_CHOICE) year = models.ForeignKey(Year, on_delete= models.SET_NULL) class Student(models.Model): name = models.CharField(max_length=266) admission_month = models.ForeignKey(Month, on_delete=models.SET_NULL) you can proceed with this approach also... On Wednesday, June 16, 2021 at 2:37:34 PM UTC-7 adesolar...@gmail.com wrote: > Good day, > Please how can this be achieved? > Best regards. > > On Wed, Jun 16, 2021, 7:01 PM Ridwan Adeyemo <adesolar...@gmail.com> > wrote: > >> Thanks man.👍 >> >> On Wed, Jun 16, 2021, 5:22 PM Ayush Bisht <bisht.a...@gmail.com> wrote: >> >>> I think you are trying to sum up the value of two model fields and store >>> them in some other field. >>> >>> >>> so for that u can proceed from base. >>> >>> simple you just have to update that field in save method >>> >>> for example : >>> *class Student(models.Model):* >>> maths_score = models.DecimalField() >>> english_score = models.DecimalFIeld() >>> Total_score = models.DecimalField(default = 0) >>> >>> *def save(self, *args, **kwargs):* >>> * self.Total_score = self.maths_score + self.english_score* >>> super(Student, self).save(*args, **kwargs) >>> >>> >>> >>> or you can proceed with clean() method also. >>> On Tuesday, June 15, 2021 at 11:34:37 AM UTC-7 adesolar...@gmail.com >>> wrote: >>> >>>> How do I add two models together in the database, two different >>>> DecimalField. >>>> i.e math_score + eng_score = total_score >>>> >>> -- >>> You received this message because you are subscribed to a topic in the >>> Google Groups "Django users" group. >>> To unsubscribe from this topic, visit >>> https://groups.google.com/d/topic/django-users/qsaj_ELIfgA/unsubscribe. >>> To unsubscribe from this group and all its topics, send an email to >>> django-users...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-users/81d7b7b1-9521-47b1-9fef-91be3ba4c952n%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/django-users/81d7b7b1-9521-47b1-9fef-91be3ba4c952n%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/41290c5b-17f5-4be5-94a2-5ba9db079b02n%40googlegroups.com.