Questions tagged [django-modeladmin]

132 questions
4
votes
3 answers

How to get the inline objects in the save method in models.py

I have the class Invoice, which (simplified) has the following attributes: class Invoice(models.Model) number = models.CharField(verbose_name="Number", max_length=16) issue_date = models.DateTimeField(verbose_name="Issue date",…
4
votes
1 answer

How to add a line number to each row of a tabularinline block

I have a ModelAdmin class with an inline of type TabularInline. What I would like is for each row of the TabularInline to have a line number displayed to the left of it. This number would increment as new records are added to the inline, and would…
rhoward99
  • 59
  • 3
4
votes
3 answers

Django - ForeignKey field initial value definition in Admin

I have a Person model, which has a ForeignKey field to itself, called mother. When the user goes to the 'add' admin form, I want to define an initial value for mother, in case there is a GET('mother') parameter, or leave it blank, in case there is…
3
votes
1 answer

Django - ModelAdmin media definition

I'm trying to include some CSS and JS files into the change form of an object like specified in the doc. Here are me files: admin.py #... class ScribPartAdmin(admin.ModelAdmin): class Media: css = { 'all': ('mymarkup.css',) } js…
Pierre de LESPINAY
  • 44,700
  • 57
  • 210
  • 307
3
votes
2 answers

Evaluate a readonly field upon creating a new object in Django 1.11 admin

Assuming a the following model # models.py class Person(models.Model): name = models.CharField(max_length=40) birthdate = models.DateField() age = models.CharField(max_length=3) # dont mind the type, this is just an example :) The…
Demetris
  • 2,981
  • 2
  • 25
  • 33
3
votes
1 answer

Wagtail ModelAdmin > how to set initial data for an InlinePanel?

I have created a Planning and a Meeting model. I use Wagtail's ModelAdmin to administer them. Planning has a planning_panels which is an InlinePanel. For other models I can set initial data using the form's __init__ method. But I can't figure out…
Robert
  • 261
  • 2
  • 11
3
votes
1 answer

Limiting the options of foreign key in ModelAdmin returns "Select a valid choice"

I am attempting to limit the option to a foreign key in the admin app for a specific user (The field that i am trying to limit is called school) . This is what my code looks like - Unfortunately there are two problems (mentioned below) when I…
James Franco
  • 4,516
  • 10
  • 38
  • 80
3
votes
0 answers

Create dynamic model in Django 1.8

How to create Dynamic models in Django 1.8? I have done the following according to the official site: >>attrs = { 'name': models.CharField(max_length=32), '__module__': 'myapp.models' } >>person = type("ptable",…
3
votes
1 answer

Why does Django keeps asking content types are stale and need to be deleted

I've tried everything found: Can stale content types be automatically deleted in Django? Deleting unused Models, stale content types prompt InvalidBasesError: Cannot resolve bases for [] Django Wagtail CMS migrate:…
Olivier Pons
  • 15,363
  • 26
  • 117
  • 213
3
votes
1 answer

Edit field from ForeignKey in Admin

class BoxItem(models.Model): quantity = models.IntegerField() class Box(models.Model): name = models.CharField(max_lenght=150) item = models.ForeignKey(BoxItem) admin: admin.site.register(BoxItem) admin.site.register(Box) How can I…
3
votes
0 answers

Override the Admin.py file of reusable app in Django

I basically have 2 external Django app that are overriding the UserAdmin model. Each one of these will first unregister the UserAdmin model and then register their own, something like…
Leonardo
  • 4,046
  • 5
  • 44
  • 85
3
votes
2 answers

Django app tables not visible in admin UI

Gist - Tables have been successfully created from model but not visible in admin UI - Environment - Windows 7, Python 2.7, VirtualEnv, SQLite I have a couple of models defined in my django app. Here is the relevant content of the model.py file from…
Shreyas
  • 1,410
  • 3
  • 11
  • 15
2
votes
1 answer

how to validation fields for TabularInline in django admin?

I create a BaseInlineFormSet like this: class ProductPictureRequiredFormSet(forms.models.BaseInlineFormSet): def clean(self): if self.cleaned_data["image"] == None: raise ValidationError("error") return…
Mahdi Kh
  • 29
  • 4
2
votes
2 answers

Django - Include a media into a specific admin page

If I have this kind of modelAdmin: admin.py #... class ScribPartAdmin(admin.ModelAdmin): class Media: css = { 'all': ('css/mymarkup.css',) } admin.site.register(ScribPart, ScribPartAdmin) #... mymarkup.css is actually included in…
Pierre de LESPINAY
  • 44,700
  • 57
  • 210
  • 307
2
votes
3 answers

How to prevent Error: 403 in ModelAdmin.autocomplete_fields?

ModelAdmin.autocomplete_fields looks to be very simple to implement into the Django admin: class UserAdmin(admin.ModelAdmin): autocomplete_fields = ['material'] admin.site.register(User, UserAdmin) class MaterialAdmin(admin.ModelAdmin): …
1
2
3
8 9