Opened 12 years ago
Closed 12 years ago
#21593 closed Bug (duplicate)
Can't restrict formfield_for_manytomany queryset if the m2m field is django.contrib.auth.models.User
| Reported by: | Giacomo Graziosi | Owned by: | nobody |
|---|---|---|---|
| Component: | contrib.admin | Version: | 1.6 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
This is an example showing the odd behaviour:
from django.contrib import admin
from django.contrib.auth.models import User
from models import Article, AM2MField
class RestrictedModelAdmin(admin.ModelAdmin):
def formfield_for_manytomany(self, db_field, request, **kwargs):
if db_field.name == 'users':
kwargs['queryset'] = User.objects.filter(username="user1")
if db_field.name == 'am2m':
kwargs['queryset'] = AM2MField.objects.filter(name="m1")
return super(RestrictedModelAdmin, self).formfield_for_manytomany(db_field, request, **kwargs)
admin.site.register(Article, RestrictedModelAdmin)
admin.site.register(AM2MField)
from django.db import models
from django.contrib.auth.models import User
class AM2MField(models.Model):
name = models.CharField(max_length=255)
class Article(models.Model):
am2m = models.ManyToManyField(AM2MField)
users = models.ManyToManyField(User)
The Users field is showing all of the system users, ignoring the filtering.
Change History (2)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
This is a duplicate of #21405. The fix was backported to the 1.6 branch and should be part of the 1.6.1 release.
Note:
See TracTickets
for help on using tickets.
The bug seems to be fixed in the master version.