If you are talking about Django's admin couldn't you implement it by
overriding save_model as your subject seems to suggest?

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model

<http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model>If
you are talking about just a regular form then you could pass the request to
the form and then validate based on that. Something like the following:

from django import forms

class PersonForm(forms.ModelForm):
    def __init__(self, request, *args, **kwargs):
        super(PersonForm, self).__init__(*args, **kwargs)
        self.request = request

    def clean(self):
        if self.instance.user != self.request.user:
            raise forms.ValidationError("You can't edit someone else's
Person record!!")
        return super(PersonForm, self).clean()

    class Meta:
        model = Person
        exclude = ('user',)

On Tue, Apr 13, 2010 at 6:06 PM, Alfredo Alessandrini
<alfreal...@gmail.com>wrote:

> Hi,
>
> I've this model:
>
> class Person(models.Model):
>    user = models.ForeignKey(User)
>    courses = models.TextField(blank=True, null=True)
>    research_statement = models.TextField(blank=True, null=True)
>    ..........
>    ............
>
> I will let to save the form only when the user is making changes its
> model (user=request.user).
>
>
> Thanks,
>
> Alfredo
>
> --
> 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.
>
>


-- 
=======================================
株式会社ビープラウド  イアン・ルイス
〒150-0021
東京都渋谷区恵比寿西2-3-2 NSビル6階
email: ianmle...@beproud.jp
TEL:03-6416-9836
FAX:03-6416-9837
http://www.beproud.jp/
=======================================

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