Hello,
I have the following classes:
class Application(models.Model):
users = models.ManyToManyField(User, through='Permission')
folder = models.ForeignKey(Folder)
class Folder(models.Model):
company = models.ManyToManyField(Compnay)
class UserProfile(models.Model):
user = models.OneToOneField(User, related_name='profile')
company = models.ManyToManyField(Company)
Now when I save application, I would like to check if the users do not
belong to the application's folder's companies.
I have posed this question before and someone came up with the
following sollution:
forms.py:
class ApplicationForm(ModelForm):
class Meta:
model = Application
def clean(self):
cleaned_data = self.cleaned_data
users = cleaned_data['users']
folder = cleaned_data['folder']
if
users.filter(profile__company__in=folder.company.all()).count() > 0:
raise forms.ValidationError('One of the users of this
Application works in one of the Folder companies!')
return cleaned_data
admin.py
class ApplicationAdmin(ModelAdmin):
form = ApplicationForm
This seems like right the way to go about this. The problem is that
neither the users nor folder fields are in the cleaned_data and I get
a keyerror when it hits the users = cleaned_data['users'] line.
I was hoping that someone here could explain to me why these
manytomany fields don't show up in cleaned_data and that someone could
possibly give me a sollution to my problem.
Thanks!
Heleen
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.