django-admin

Add context to every Django Admin page

微笑、不失礼 提交于 2021-02-07 12:16:30
问题 How do I add extra context to all admin webpages? I use default Django Admin for my admin part of a site. Here is an url entry for admin: urlpatterns = [ url(r'^admin/', admin.site.urls), ] And my apps register their standard view models using: admin.site.register(Tag, TagAdmin) My problem, is that I want to display an extra field in admin template header bar and I have no idea how to add this extra context. My first bet was adding it in url patterns like below: urlpatterns = [ url(r'^admin/'

InlineFormSet with queryset of different model

旧巷老猫 提交于 2021-02-07 10:24:27
问题 What we're trying to do is populate a list of inline forms with initial values using some queryset of a different model. We have products, metrics (some category or type or rating), and a rating, which stores the actual rating and ties metrics to products. class Product(models.Model): name = models.CharField(max_length=100) price = models.IntegerField(max_length=6) class Metric(models.Model): name = models.CharField(max_length=80) description = models.TextField() class Rating(models.Model)

InlineFormSet with queryset of different model

给你一囗甜甜゛ 提交于 2021-02-07 10:22:32
问题 What we're trying to do is populate a list of inline forms with initial values using some queryset of a different model. We have products, metrics (some category or type or rating), and a rating, which stores the actual rating and ties metrics to products. class Product(models.Model): name = models.CharField(max_length=100) price = models.IntegerField(max_length=6) class Metric(models.Model): name = models.CharField(max_length=80) description = models.TextField() class Rating(models.Model)

InlineFormSet with queryset of different model

依然范特西╮ 提交于 2021-02-07 10:22:30
问题 What we're trying to do is populate a list of inline forms with initial values using some queryset of a different model. We have products, metrics (some category or type or rating), and a rating, which stores the actual rating and ties metrics to products. class Product(models.Model): name = models.CharField(max_length=100) price = models.IntegerField(max_length=6) class Metric(models.Model): name = models.CharField(max_length=80) description = models.TextField() class Rating(models.Model)

InlineFormSet with queryset of different model

旧城冷巷雨未停 提交于 2021-02-07 10:21:04
问题 What we're trying to do is populate a list of inline forms with initial values using some queryset of a different model. We have products, metrics (some category or type or rating), and a rating, which stores the actual rating and ties metrics to products. class Product(models.Model): name = models.CharField(max_length=100) price = models.IntegerField(max_length=6) class Metric(models.Model): name = models.CharField(max_length=80) description = models.TextField() class Rating(models.Model)

Django how to enter multiple records on one form

冷暖自知 提交于 2021-02-07 08:00:27
问题 I am writing a calendar app with the following models: class CalendarHour(models.Model): ''' Each day there are many events, e.g. at 10 am, the framer orders material, etc. ''' day_id = models.ForeignKey(CalendarDay) time = models.TimeField() work = models.TextField() def __unicode__(self): return 'work that took place at {work_time}'.format(work_time = self.time) class CalendarDay(models.Model): ''' Each project has so many daily logs. But, each daily log belongs to only one project

Django how to enter multiple records on one form

心已入冬 提交于 2021-02-07 07:58:22
问题 I am writing a calendar app with the following models: class CalendarHour(models.Model): ''' Each day there are many events, e.g. at 10 am, the framer orders material, etc. ''' day_id = models.ForeignKey(CalendarDay) time = models.TimeField() work = models.TextField() def __unicode__(self): return 'work that took place at {work_time}'.format(work_time = self.time) class CalendarDay(models.Model): ''' Each project has so many daily logs. But, each daily log belongs to only one project

Adding custom action to UserModel's Admin page

可紊 提交于 2021-02-07 06:39:11
问题 Is there any possibility to create custom action in admin page for django UserModel? I want automatize adding user to group (like adding him to staff, set some extra values, etc.), and of course create actions that take these changes back. Thanks for your help. 回答1: Import User in your admin.py unregister it, create new ModelAdmin for it (or subclass the default one) and go wild. It would look something like this I guess: from django.contrib.auth.models import User class UserAdmin(admin

django admin override filter_horizontal

左心房为你撑大大i 提交于 2021-02-07 03:53:28
问题 I'm aiming to make an "advanced" filter_horizontal, one with more filters, but I can't seem to find the widget to override. I know it uses the related_widget_wrapper.html, but if I want to add functionalities to it in a clear way, what is the widget to override. For now my backup solution is to do a full javascript solution to prepend it with a dropdown on form load (created from javascript) and make ajax calls to modify the filter...but this seems as an overkill. What i've done so far : #

django admin override filter_horizontal

三世轮回 提交于 2021-02-07 03:52:25
问题 I'm aiming to make an "advanced" filter_horizontal, one with more filters, but I can't seem to find the widget to override. I know it uses the related_widget_wrapper.html, but if I want to add functionalities to it in a clear way, what is the widget to override. For now my backup solution is to do a full javascript solution to prepend it with a dropdown on form load (created from javascript) and make ajax calls to modify the filter...but this seems as an overkill. What i've done so far : #