A model is just a class, so the methods just "go there", yes.
You could check out apps in django.contrib for styling best practices (the django doc itself also covers this I think, but I can't remember where)
Le 17 juil. 2012 19:49, "jeffsarge" <jeff@sargetv.com> a écrit :
-- Hi,I'm learning Django and Python at the same time. Going through the Django tutorial (writing your first Django app)Going smooth until I hit the part where I need to add a unicode method to both Poll and Choice:def __unicode__(self):return self.questionsame with the custom methods that are supposed to be added (def was_published_recently(self):Do these just get stuck onto the end of my class Poll(models.Model):? like this...class Poll(models.Model):question = models.CharField(max_length=200)pub_date = models.DateTimeField('date published')def __unicode__(self):return self.questiondef was_published_recently(self):return self.pub_date >= timezone.now() - datetime.timedelta(days=1)I'm not sure what the correct way is to add this code to the python classes I created earlier in the polls/models.pyAny ideas?thanks,Jeff--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/2h8gM7CDls8J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment