django-admin

Django import-export choices field

梦想的初衷 提交于 2020-01-15 05:18:26
问题 I have a model with choices list ( models.py ): class Product(models.Model): ... UNITS_L = 1 UNITS_SL = 2 UNITS_XL = 3 PRODUCT_SIZE_CHOICES = ( (UNITS_L, _('L')), (UNITS_SL, _('SL')), (UNITS_XL), _('XL'), ) product_size = models.IntegerField(choices=PRODUCT_SIZE_CHOICES) ... Also I added a new class for exporting needed fields( admin.py ): from import_export import resources, fields ... Class ProductReport(resources.ModelResource): product_size = fields.Field() class Meta: model = Product #I

Edit Django User admin template

[亡魂溺海] 提交于 2020-01-14 18:45:09
问题 I need to edit the template shown for editing a specific user. I need to display some additional data that doesn't fit in with an include-style. I apologise for the short question... but that's pretty much all there is at the moment. 回答1: If you can't accomplish what you want with just subclassing admin.ModelAdmin , you can create a directory "admin/auth" in your template directory and put a "change_form.html" in there. In this template you can override blocks that are available e.g. {% block

Django admin search_fields with model property

主宰稳场 提交于 2020-01-14 13:37:24
问题 I'm trying to use a property in my model as a field in django admin (1.2). Here's an example of my code: class Case(models.Model): reference = models.CharField(_(u'Reference'), max_length=70) client_read = models.BooleanField(default=0) def __unicode__(self): return self.case_id @property def case_id(self): """ unique case ID """ number = (settings.CASE_ID_LENGTH - len(str(self.id))) * "0" + str(self.id) return '%(year)s%(unique_id)s' % { 'year': self.case_date.strftime("%y"), 'month': self

Auto Generated Slugs in Django Admin

血红的双手。 提交于 2020-01-14 05:57:09
问题 I have an app that will one day allow front-end crud, which will create the slug with slugify . Right now though, all the object creation is being done in the admin area and I was wondering if there is a way to auto generate slugs while creating and saving an object from within admin? Here is the method for slugify for the front-end; not sure if its even relevant. Thank you. def create_slug(instance, new_slug=None): slug = slugify(instance.title) if new_slug is not None: slug = new_slug qs =

Django InlineModelAdmin gives error 'MediaDefiningClass' object is not iterable

情到浓时终转凉″ 提交于 2020-01-14 01:58:48
问题 From models.py class Indicator(models.Model): name = models.CharField(max_length=50) youtube = models.CharField(max_length=LONG_BLOG_POST_CHAR_LEN) description = models.CharField(max_length=LONG_BLOG_POST_CHAR_LEN) recommendation = models.CharField(max_length=LONG_BLOG_POST_CHAR_LEN) isPublic = models.BooleanField(default=False) methods_path = models.CharField(max_length=100,default=None) meta_description = models.CharField(max_length=150,default='') image_path = models.CharField(max_length

Django admin site with mongodb

只谈情不闲聊 提交于 2020-01-13 14:04:28
问题 I am using django with mongodb through django-mongodb. I was able to set up the django admin site (through the fixes on the troubleshooting page), now when I use the admin site I am able to view all of the top-level fields, but (somewhat as expected) the embedded objects and lists are not able to be viewed, they just show up as a print would show them, "List Object" for example. Is there any way to use the admin interface to view the sub-models etc...? If there is no convenient third-party

Django inline - allow adding disable editing

老子叫甜甜 提交于 2020-01-13 11:38:31
问题 Hi. I am asking this question after reading the following questions: Question_1 and Question_2. Question_1 doesn't have any appropriate answers and Question_2 is having an alternative solution but not a perfect solution. Here I have two models and admins for them. models.py class TaskList(models.Model): task_name = models.CharField(max_length = 255, unique = True) description = models.TextField() assignee_role = models.ForeignKey(Group, related_name = "assignee_roles") assignee_name = models

Django model field default based on another model field

丶灬走出姿态 提交于 2020-01-13 10:21:53
问题 I use Django Admin to build a management site. There are two tables, one is ModelA with data in it, another is ModelB with nothing in it. If one model field b_b in ModelB is None, it can be displayed on the webpage with the value of ModelA 's field a_b . I don't know how to do it, Here is the pseudo code: In models.py from django.db import models class ModelA(models.Model): a_a = models.CharField(max_length=6) a_b = models.CharField(max_length=6) class ModelB(models.Model): modela = models

How can I customize the display of a model using contenttypes in the admin?

孤人 提交于 2020-01-13 09:52:11
问题 I have these models: class App(models.Model): name = models.CharField(max_length=100) class ProjectA(models.Model): name = models.CharField(max_length=100) app = models.ForeignKey(App) class ProjectB(ProjectA): pass class Attachment(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() project = generic.GenericForeignKey("content_type","object_id") file = models.FileField(upload_to=".") I'm registering all the models for the admin, and I'm

Django admin add custom filter

梦想与她 提交于 2020-01-13 07:38:08
问题 i'm using django 1.10 and I need to display data and create a filter based on a value from a different model(which has a foreign key referencing my model that is used on the admin template) These are my 2 models: This one is used to generate the template: class Job(models.Model): company = models.ForeignKey(Company) title = models.CharField(max_length=100, blank=False) description = models.TextField(blank=False, default='') store = models.CharField(max_length=100, blank=True, default='')