Your error is this...
def save(self,*args,**kwargs):
       if not self.start_date:
           self.start_date=models.DateField(datetime.date.today())
           year=timedelta(days=365)
           self.expire_date=models.DateField(datetime.date.today()
+year)



On Thu, Jun 17, 2010 at 8:40 AM, Sheena <sheena.oconn...@gmail.com> wrote:

> Thanks
>
> The question is how do I populate a field with some other date, for
> example, there's a date of birth field that the auto stuff wont be
> ideal for...
> In the populate method i mentioned before, i passed the dob(date of
> birth) field a Date object initialized to something arbitrary. Does
> the DateField not get along with standard date objects? What format
> should stuff be in for populating DateFields?
>
> On Jun 17, 7:24 am, Alexander Jeliuc <jeliucalexa...@gmail.com> wrote:
> > read about autofill_now=True and autofill=True
> >
> > On Thu, Jun 17, 2010 at 8:14 AM, Sheena <sheena.oconn...@gmail.com>
> wrote:
> > > I've defined a number of models, one of which I've called
> > > MemberProfile that looks like this
> >
> > > class MemberProfile(models.Model):
> > >    postal_addr1=models.CharField(max_length=50, verbose_name="postal
> > > address line 1")
> > >    postal_addr2=models.CharField(max_length=50, verbose_name="postal
> > > address line 2")
> > >    postal_addr3=models.CharField(max_length=50, verbose_name="postal
> > > address line 3")
> > >    postalcode=models.CharField(max_length=4, verbose_name="postal
> > > code")
> > >    res_addr1=models.CharField(max_length=50,
> > > verbose_name="residential address line 1")
> > >    res_addr2=models.CharField(max_length=50,
> > > verbose_name="residential address line 2")
> > >    res_addr3=models.CharField(max_length=50,
> > > verbose_name="residential address line 3")
> > >    rescode=models.CharField(max_length=4, verbose_name="residential
> > > postal code")
> > >    homeno=models.CharField(max_length=12, verbose_name="home number")
> > >    workno=models.CharField(max_length=12, verbose_name="work number")
> > >    cellno=models.CharField(max_length=12, unique=True,
> > > verbose_name="cellphone number")
> > >    idno=models.CharField(max_length=13, unique=True, verbose_name="id
> > > or passport number")
> > >    occu=models.CharField(max_length=15, verbose_name="occupation")
> > >    employer=models.CharField(max_length=30)
> > >    amount_paid=models.IntegerField(blank=True, null=True,
> > > help_text="total fees paid to date", verbose_name="total reciepts")
> > >    reciept_no=models.IntegerField(blank=True, null=True,
> > > help_text="latest reciept number", verbose_name="reciept number")
> > >    dob=models.DateField(verbose_name="date of birth")
> > >    start_date=models.DateField()
> > >    expire_date=models.DateField()
> > >    captured_by=models.CharField(max_length=50, help_text="name of
> > > data capturer")
> > >    photo=models.ImageField(upload_to="memberphotos", null=True,
> > > blank=True)
> > >    permission=models.CharField(max_length=1,
> > > choices=PERMISSION_CHOICES, help_text="Administration level, if the
> > > user is a superuser this field has no effect")
> > >    user=models.ForeignKey(User,unique=True,related_name="member",
> > > editable=False)
> > >    branch=models.ForeignKey(Branch,related_name="member", null=True)
> >
> > >    def create_member(self,username,email,password):
> > >        m=MemberProfile()
> >
> > >
> m.user=User.objects.create_user(username=username,email=email,password=password)
> > >        return m
> >
> > >    def __unicode__(self):
> > >        return self.user.username
> >
> > >    def save(self,*args,**kwargs):
> > >        if not self.start_date:
> > >            self.start_date=models.DateField(datetime.date.today())
> > >            year=timedelta(days=365)
> > >            self.expire_date=models.DateField(datetime.date.today()
> > > +year)
> > >        super(MemberProfile, self).save(self,*args,**kwargs)
> >
> > > I then wrote a method called populate just to test the database out
> > > and it is pretty friendly until I get this:
> >
> > > Traceback (most recent call last):
> > >  File "<console>", line 1, in <module>
> > >  File "/host/Shared info/MyDBA/MyMembers/populate.py", line 114, in
> > > populate
> > >    m1.save()
> > >  File "/host/Shared info/MyDBA/MyMembers/../MyMembers/chiefs/
> > > models.py", line 115, in save
> > >    super(MemberProfile, self).save(self,*args,**kwargs)
> > >  File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line
> > > 410, in save
> > >    self.save_base(force_insert=force_insert,
> > > force_update=force_update)
> > >  File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line
> > > 483, in save_base
> > >    values = [(f, f.get_db_prep_save(raw and getattr(self, f.attname)
> > > or f.pre_save(self, True))) for f in meta.local_fields if not
> > > isinstance(f, AutoField)]
> > >  File "/usr/lib/pymodules/python2.6/django/db/models/fields/
> > > __init__.py", line 192, in get_db_prep_save
> > >    return self.get_db_prep_value(value)
> > >  File "/usr/lib/pymodules/python2.6/django/db/models/fields/
> > > __init__.py", line 511, in get_db_prep_value
> > >    return connection.ops.value_to_db_date(self.to_python(value))
> > >  File "/usr/lib/pymodules/python2.6/django/db/models/fields/
> > > __init__.py", line 472, in to_python
> > >    if not ansi_date_re.search(value):
> > > TypeError: expected string or buffer
> >
> > > m1 is an instance of MemberProfile...
> >
> > > The error goes away if I comment out everything to do with
> > > DateField...
> > > Am I doing something retarded? As far as I can see I'm populating the
> > > fields the right way...
> >
> > > Any help would be greatly appreciated
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> <django-users%2bunsubscr...@googlegroups.com<django-users%252bunsubscr...@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-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@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-us...@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.

Reply via email to