Note: I am using the magic-removal branch.

I am looking for the most elegant way to use the generic CRUD views
while at the same time being able to support a hidden
django.contrib.auth.models.User field.  Here's what I'm doing now:

#----------- my model
class Item(models.Model):
    topic = models.ForeignKey(Topic)
    subject = models.CharField(maxlength=64)
    content = models.TextField()
    submit_date = models.DateTimeField('submission date',
auto_now=True)
    submitter = models.ForeignKey(User)

    class Admin:
        list_display = ('topic', 'subject', 'submit_date', 'submitter',
                        'content',)

    def __repr__(self):
        return self.subject

#----------- my view
def newitem(request):
    if request.POST:
        new_post = request.POST.copy()
        new_post['submitter'] = str(request.user.id)
        request.POST = new_post
    return create_update.create_object(
        request, model=Item, login_required=True,
        post_save_redirect='/')

Notice in the view how, when POSTing, I make a copy of the POST object,
add the hidden user field from the session, then call create_object().
This seems like a bit of a hack.  Is there a better way?


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to