django-admin

Django auth: Where to put custom templates?

扶醉桌前 提交于 2020-04-14 04:03:12
问题 I want to set up user authentication with Django (1.9). As described in the documentation I included the auth view in my project's urls.py like urlpatterns = [ ..., url('^accounts/', include('django.contrib.auth.urls')), ..., ] as the documentation describes, one needs to write custom templates for the Auth views. I put those templates in the directory myproject/templates/registration/ . The problem is now that these templates, since they follow the predefined naming convention, clash with

Django auth: Where to put custom templates?

巧了我就是萌 提交于 2020-04-14 03:58:05
问题 I want to set up user authentication with Django (1.9). As described in the documentation I included the auth view in my project's urls.py like urlpatterns = [ ..., url('^accounts/', include('django.contrib.auth.urls')), ..., ] as the documentation describes, one needs to write custom templates for the Auth views. I put those templates in the directory myproject/templates/registration/ . The problem is now that these templates, since they follow the predefined naming convention, clash with

Dynamical Form fields in __init__in Django admin

☆樱花仙子☆ 提交于 2020-04-13 18:12:12
问题 My model and form: #admin.py class SitesForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(SitesForm, self).__init__(*args, **kwargs) self.fields['mynewfield'] = forms.CharField() class SitesAdmin(admin.ModelAdmin): form = SitesForm admin.site.register(Sites,SitesAdmin) #model.py class Sites(models.Model): url = models.URLField(u'URL') is_active = models.BooleanField(default=True, blank=True) is_new = models.BooleanField(default=False, blank=True) group = models.ForeignKey(

Dynamical Form fields in __init__in Django admin

眉间皱痕 提交于 2020-04-13 18:12:03
问题 My model and form: #admin.py class SitesForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(SitesForm, self).__init__(*args, **kwargs) self.fields['mynewfield'] = forms.CharField() class SitesAdmin(admin.ModelAdmin): form = SitesForm admin.site.register(Sites,SitesAdmin) #model.py class Sites(models.Model): url = models.URLField(u'URL') is_active = models.BooleanField(default=True, blank=True) is_new = models.BooleanField(default=False, blank=True) group = models.ForeignKey(

testing admin.ModelAdmin in django

我与影子孤独终老i 提交于 2020-04-07 12:42:27
问题 I am trying to find out the best way for testing admin.ModelAdmin in admin.py . Specifically I am overriding the save_model() function which I want to test. From the research I have done, the only solution I have found was writing a request/response test and then query the database. 回答1: Check out Django's ModelAdminTests for examples. 回答2: As suggested in Udi's answer, we can study Django's own ModelAdmin tests, to determine the basic ingredients for a ModelAdmin test. Here's a summary:

Displaying both sides of a ManyToMany relationship in Django admin

旧巷老猫 提交于 2020-03-18 06:05:29
问题 Say I have the following models that have a many-to-many relationship: models.py: class Foo(models.Model): name = models.TextField() class Bar(models.Model): name = models.TextField() foos = models.ManyToManyField(Foo, related_name='bars') And then having defined them in admin in the following way: admin.py @admin.register(Foo) class FooAdmin(admin.ModelAdmin): """Foo admin.""" list_display = ('name',) search_fields = ('name',) @admin.register(Bar) class BarAdmin(admin.ModelAdmin): """Bar

How to properly override User admin in Django

让人想犯罪 __ 提交于 2020-03-02 19:33:30
问题 I want to add add inline model and exclude some fields from User change form in Django admin. I'm trying to override Django's built-in UserAdmin to preserve User change design: class UserCustomAdmin(UserAdmin): # list_display = ['id', 'username','email', 'last_login'] exclude = ['groups','user_permissions'] inlines = [UserProfileInline] Even exclude = ['groups'] raises error: u"Key 'groups' not found in 'UserForm'. Choices are: date_joined, email, first_name, is_active, is_staff, is_superuser

How to properly override User admin in Django

£可爱£侵袭症+ 提交于 2020-03-02 19:32:09
问题 I want to add add inline model and exclude some fields from User change form in Django admin. I'm trying to override Django's built-in UserAdmin to preserve User change design: class UserCustomAdmin(UserAdmin): # list_display = ['id', 'username','email', 'last_login'] exclude = ['groups','user_permissions'] inlines = [UserProfileInline] Even exclude = ['groups'] raises error: u"Key 'groups' not found in 'UserForm'. Choices are: date_joined, email, first_name, is_active, is_staff, is_superuser

Django Admin: change displayed column name in inline ManyToMany field

大兔子大兔子 提交于 2020-02-21 21:27:15
问题 I try to translate Django Admin site and I have a problem with ManyToMany TabularInline . My models.py are: class Doctor(models.Model): (...) specializations = models.ManyToManyField(Specialization, blank=True, verbose_name='Specjalizacje') class Meta: verbose_name = 'Lekarz' verbose_name_plural = 'Lekarze' class Specialization(models.Model): name = models.CharField(max_length=191, verbose_name='Nazwa') class Meta: verbose_name = 'Specjalizacja' verbose_name_plural = 'Specjalizacje' And my

Django Admin: change displayed column name in inline ManyToMany field

倾然丶 夕夏残阳落幕 提交于 2020-02-21 21:21:13
问题 I try to translate Django Admin site and I have a problem with ManyToMany TabularInline . My models.py are: class Doctor(models.Model): (...) specializations = models.ManyToManyField(Specialization, blank=True, verbose_name='Specjalizacje') class Meta: verbose_name = 'Lekarz' verbose_name_plural = 'Lekarze' class Specialization(models.Model): name = models.CharField(max_length=191, verbose_name='Nazwa') class Meta: verbose_name = 'Specjalizacja' verbose_name_plural = 'Specjalizacje' And my