On Tue, Feb 10, 2009 at 4:07 PM, bkev <krban...@gmail.com> wrote: > > Hello all, > > Is there a way to check whether a field contains a certain value in a > ManyToManyField in the admin on a custom save method? For example, I > have a model like: > > class LastName(models.Model): > lastname = models.CharField(...) > > class Person(models.Model): > firstname = models.CharField(...) > lastname = models.ManyToManyField(LastName,...) > jumbledname = models.CharField(..., editable = False) > > def save(self): > if self.lastname CONTAINS? 'Smith': > self.jumbledname = u'%s%s' % ('self.firstname, > self.lastname') > else: > self.jumbledname = self.firstname > super(Person,self).save() > > Thanks, > -bkev > > > It all depends on what you're trying to do, in that example self.lastname is just a normal python string, so you can do "Smith" in self.lastname, for different datatypes it works slightly differently.
Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---