Assuming that you set_sub_date() function just sets the publish date
to when the item was created and easy way to do this is in the model

class PressRelease(models.Model):
    pub_date = models.DateField(auto_now_add=True)

That will just set the pub_date to the current date when it is added
to the DB. Not sure if this was the functionality you were looking
for.

Cheers,

Dan

On Jul 25, 8:58 pm, djangonoob <ye.eug...@gmail.com> wrote:
> I would like to use Django's generic views for create, update, delete
> operations. However, i am start with the first step:
> the create operation.
>
> What i want to do is to use the
> django.views.generic.create_update.create_object function, using the
> form_class as the required arguments. I would like to to set the
> pub_date ( found in models.py ) as datetime.datetime.now() via
> customizing the model's form.is_valid
>
> I understand that i can set the pub_date as datetime.datetime.now()
> right in the models.py, but i would want to learn
> how to customize it using forms.
>
> How do i link the django.views.generic.create_update.create_object
> function thing to the set_pub_date function in views.py
> so that i can customize the input before saving?
>
> Or, is there any other way i can use the form_class ( with generic
> views ) so that i can customize the model's form before saving?
>
> Wth the current code found here ( and also the link to dpaste ) , i
> received the following error:
> 'ModelFormOptions' object has no attribute 'many_to_many'
>
> How do i link the django.views.generic.create_update.create_object
> function thing to the set_pub_date function in views.py
> so that i can customize the input before saving?
>
> Or, is there any other way i can use the form_class ( with generic
> views ) so that i can customize the model's form before saving?
>
> The following is my code: ( a link to django paste is 
> here:http://dpaste.com/71445/ )
>
> #urls.py
> press_detail_dict = {
>     'queryset': PressRelease.objects.all(),
>     'template_name':'press/detail.html',
>     'template_object_name':'press',
>
> }
>
> press_list_dict = {
>     'queryset': PressRelease.objects.all(),
>     'template_name':'press/press_list.html',
>     'allow_empty':False,
>     'template_object_name':'press',
>
> }
>
> press_create_dict = {
> # just a side note: on the template : press_create.html, call the form
> just by using {{ form }}
>     'form_class': PressReleaseCRUD,
>     'template_name':'press/press_create.html',
>     'post_save_redirect':'/press/list/',
>     #'extra_context':{'pub_date': set_pub_date()}
>     // the above line is commented out bcos is causes an error :
> TypeError: set_pub_date() takes exactly 1 argument (0 given)
>
> }
>
> urlpatterns = patterns('',
>     (r'^detail/(?P<pid>\d+)/$','press.views.detail'),
>
>     #using generic views -> list/detail generic views
>     (r'^list/$', 'django.views.generic.list_detail.object_list',
> press_list_dict),
>     (r'^detail/(?P<object_id>\d+)/$',
> 'django.views.generic.list_detail.object_list', press_detail_dict),
>
>     # testing django.views.generic.create_update.create_object
>     (r'^create/$', 'django.views.generic.create_update.create_object',
> press_create_dict),
>
>     #using generic views redirect
>     #(r'$','django.views.generic.simple.redirect_to',{'url':'/press/
> list/'})
>
> )
>
> # views.py
> class PressRelease(models.Model):
>     title = models.CharField(max_length=100)
>     body = models.TextField()
>     pub_date = models.DateField()
>     author = models.CharField(max_length=100)
>
>     def __unicode__(self):
>         return self.title
>
> class PressReleaseCRUD(ModelForm):
>     class meta:
>         model = PressRelease
>         exclude = ['pub_date']
>
> # press_create.html
> <form action="" method="post">
> <p>{{ form.as_p }}</p>
> <input type="submit" value="Submit" />
> </form>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to