On 15 July 2010 21:10, rahul jain <[email protected]> wrote: > anyone on this ? > > On Tue, Jul 13, 2010 at 2:44 PM, rahul jain <[email protected]> > wrote: > > Could it be generic ?. I mean i don't want to specify self.naughty_field. > > > > How to do it for self.any_field ? > > > > RJ > > > > On Tue, Jun 29, 2010 at 9:29 AM, [email protected] > > <[email protected]> wrote: > >> Django admin can't differentiate between empty string and None and > >> picks empty string which makes sense in most cases. > >> > >> If you don't like the idea of empty string override the save method > >> and coerce empty string to None before calling the super classes save, > >> e.g. > >> > >> class YourModel(models.Model): > >> ... > >> > >> def save(self, *args, **kwargs): > >> if self.naughty_field == '': > >> self.naughty_field = None > >> super(YourModel, self).save(*args, **kwargs) > >> > >> Euan > >> > >> On Jun 29, 4:15 pm, rahul jain <[email protected]> wrote: > >>> Hi there ! > >>> > >>> One of my model fields attribute is set to null="true" to allow None > >>> values. But if I use admin to save those model objects and leave it > >>> blank, it saves blank value instead of None. > >>> How to fix this ? > >>> > >>> And Blank value is not None. Blank is "" (empty) but None is NULL in > databases. > >>> > >>> -RJ >
Have a look at: http://www.mail-archive.com/[email protected]/msg16095.html some useful pointers on what fields are and how to access them. Also: http://stackoverflow.com/questions/3159614/iterating-through-model-fields-django -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

