Re: How to access SplitDateTime field elements in template
I have found a workaroud to this, by using the AdminSplitDateTime widget and then rendering field in the template, the right thing happens: in form code: from django.contrib.admin import widgets as adminWidgets class Dummy1Form(forms.ModelForm): name = forms.CharField(max_length = 100) created = forms.SplitDateTimeField(initial=datetime.datetime.now (), widget=adminWidgets.AdminSplitDateTime) in template: {% trans "Created:" %} {{ form.created }} I'm still curious on the original question though Rob On Dec 22, 12:45 pm, rtmie <robm...@yahoo.com> wrote: > I have a form with a SplitDateTimeField and cannot figure out how to > access the individual date and time elements in it from my template: > > class Dummy1(models.Model): > name = models.CharField(max_length = 100) > created = models.DateTimeField(default = datetime.datetime.now()) > > class Dummy1Form(forms.Form): > name = forms.CharField(max_length = 100) > created = forms.SplitDateTimeField(widget=forms.SplitDateTimeWidget > ()) > class Meta: > model = Dummy1 > > In my template: > {% trans "Created:" %} label> > > {{ form.created }} > > will give me access to the 2 fields but if I want to do something > like the old form , what syntax do I need to get at the individual > elements: > > {% trans "Created:" %} label> > > {% trans "Date: "%}{{ form.created_date }} > > {% trans "Time: "%}{{ form.created_time }} > > > I haven't found any doc on this > > Rgds > Rob --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to access SplitDateTime field elements in template
I have a form with a SplitDateTimeField and cannot figure out how to access the individual date and time elements in it from my template: class Dummy1(models.Model): name = models.CharField(max_length = 100) created = models.DateTimeField(default = datetime.datetime.now()) class Dummy1Form(forms.Form): name = forms.CharField(max_length = 100) created = forms.SplitDateTimeField(widget=forms.SplitDateTimeWidget ()) class Meta: model = Dummy1 In my template: {% trans "Created:" %} {{ form.created }} will give me access to the 2 fields but if I want to do something like the old form , what syntax do I need to get at the individual elements: {% trans "Created:" %} {% trans "Date: "%}{{ form.created_date }} {% trans "Time: "%}{{ form.created_time }} I haven't found any doc on this Rgds Rob --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Problem with field validation in 1.02
OK, got it working: changed view code to: if request.method =='POST': form = AppUserForm(request.POST,request.FILES) On Dec 15, 2:48 pm, rtmie <robm...@yahoo.com> wrote: > H i , > I am trying to migrate a project from 0.95 to 1.02 and so have to > migrate all of my old model based validator stuff in the new forms > style( my first encounter with the new forms style). > > I am having a problem with the following: > > in my model I have a AppUser class, with username , password , email > etc and I have a requirement that the username be unique , regardless > of case. I have a valifdation funtion to check this and raise a > ValidationError, > however when I call it with a duplicate name via form.isValid() I get > a return value of False (i.e validation failed as expected) BUT the > form.errors list is empty. I am obviously doing something dumb, but > can't for the life of me figure it out. > > Model: > > class AppUser(models.Model): > name = models.CharField(_('name'), > max_length=100, > db_column='name', > unique=True) > email = models.EmailField(_('email'), > db_column='email', > blank=True, > max_length=320) > password = models.CharField(_('password'), > max_length=30, > db_column='password') > > Form: > class AppUserForm(ModelForm): > class Meta: > model = AppUser > > def clean_name(self): > name = self.cleaned_data["name"] > if self.instance.id: > cps = AppUser.objects.exclude(id__exact=self.instance.id) > else: > cps = AppUser.objects.all() > for index in range(0,len(cps)): > if upper(cps[index].name) == upper(name): > raise forms.ValidationError, "App user name must > be unique, regardless of \ > case" > return name > > View: > > def createUser(request): > form = AppUserForm() > if request.method =='POST': > form.data = request.POST > if form.is_valid(): > log.debug("saving valid user") > cp = form.save(True) > else: > log.error( form.errors) > log.error("error list: %s" , str(form.errors)) > log.error("failed App User validation ") > > log output > app 2008-12-15 14:46:26,384 [ERROR] error list: > app 2008-12-15 14:46:26,384 [ERROR] failed CP validation --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Problem with field validation in 1.02
H i , I am trying to migrate a project from 0.95 to 1.02 and so have to migrate all of my old model based validator stuff in the new forms style( my first encounter with the new forms style). I am having a problem with the following: in my model I have a AppUser class, with username , password , email etc and I have a requirement that the username be unique , regardless of case. I have a valifdation funtion to check this and raise a ValidationError, however when I call it with a duplicate name via form.isValid() I get a return value of False (i.e validation failed as expected) BUT the form.errors list is empty. I am obviously doing something dumb, but can't for the life of me figure it out. Can anyone see if I am missing some step: Model: class AppUser(models.Model): name = models.CharField(_('name'), max_length=100, db_column='name', unique=True) email = models.EmailField(_('email'), db_column='email', blank=True, max_length=320) password = models.CharField(_('password'), max_length=30, db_column='password') Form: class AppUserForm(ModelForm): class Meta: model = AppUser def clean_name(self): name = self.cleaned_data["name"] if self.instance.id: cps = AppUser.objects.exclude(id__exact=self.instance.id) else: cps = AppUser.objects.all() for index in range(0,len(cps)): if upper(cps[index].name) == upper(name): raise forms.ValidationError, "App user name must be unique, regardless of \ case" return name View: def createUser(request): form = AppUserForm() if request.method =='POST': form.data = request.POST if form.is_valid(): log.debug("saving valid user") cp = form.save(True) else: log.error( form.errors) log.error("error list: %s" , str(form.errors)) log.error("failed App User validation ") log output app2008-12-15 14:46:26,384 [ERROR] error list:<-- expected to see something here app2008-12-15 14:46:26,384 [ERROR] failed CP validation --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Problem with field validation in 1.02
H i , I am trying to migrate a project from 0.95 to 1.02 and so have to migrate all of my old model based validator stuff in the new forms style( my first encounter with the new forms style). I am having a problem with the following: in my model I have a AppUser class, with username , password , email etc and I have a requirement that the username be unique , regardless of case. I have a valifdation funtion to check this and raise a ValidationError, however when I call it with a duplicate name via form.isValid() I get a return value of False (i.e validation failed as expected) BUT the form.errors list is empty. I am obviously doing something dumb, but can't for the life of me figure it out. Model: class AppUser(models.Model): name = models.CharField(_('name'), max_length=100, db_column='name', unique=True) email = models.EmailField(_('email'), db_column='email', blank=True, max_length=320) password = models.CharField(_('password'), max_length=30, db_column='password') Form: class AppUserForm(ModelForm): class Meta: model = AppUser def clean_name(self): name = self.cleaned_data["name"] if self.instance.id: cps = AppUser.objects.exclude(id__exact=self.instance.id) else: cps = AppUser.objects.all() for index in range(0,len(cps)): if upper(cps[index].name) == upper(name): raise forms.ValidationError, "App user name must be unique, regardless of \ case" return name View: def createUser(request): form = AppUserForm() if request.method =='POST': form.data = request.POST if form.is_valid(): log.debug("saving valid user") cp = form.save(True) else: log.error( form.errors) log.error("error list: %s" , str(form.errors)) log.error("failed App User validation ") log output app2008-12-15 14:46:26,384 [ERROR] error list: app2008-12-15 14:46:26,384 [ERROR] failed CP validation --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to save file with name based on PK of DB entry
Hi, I would like to be able to do the following: Upload a file to my app along with some meta data. Store the filepath in the table using a FileField. However I would like to override the uploaded filename to be used in the file store to some unique system generated, preferrably numeric, name. I would have thought this would be done something like: new_data['fileLocation_file']['filename'] = Item.id However I guess that the Item.id will not exist until after I call the save method for the item, and the save method will do both the database entry and the file save. Is there an easy way to override this behaviour? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---