Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change field or model attributes of a third-party Django app?

Let's say, I use django.contrib.flatpages, or any other third-party app in my project. I want to change some of this app's model attributes - for example, verbose_name. How can I do that?

like image 530
user655136 Avatar asked Jun 16 '11 06:06

user655136


People also ask

How to define primary key in Django models?

If you'd like to specify a custom primary key, specify primary_key=True on one of your fields. If Django sees you've explicitly set Field.primary_key , it won't add the automatic id column. Each model requires exactly one field to have primary_key=True (either explicitly declared or automatically added).

How to use models Django?

To use the model in the Django admin, we need to makemigrations and create the model that maps to a single database table. Now with the table created, we can migrate the model so all of the information uploaded to the model will be saved to the Django database, db.

What is my Django app name?

An app name is just the name of the Python module. Nothing more. A python module name is the case name of the root folder of the module, that must contains an init.py file. If you want to know what this name is, go to your site-packages folder and look for your module.


2 Answers

The simple answer is "don't"; use a proxy model instead.

like image 128
Ignacio Vazquez-Abrams Avatar answered Sep 24 '22 02:09

Ignacio Vazquez-Abrams


It depends. If you want to add some new fields, you can create another model with OneToOneField. If you want to add some methods, ordering etc., use proxy model. If you want to change some DB restrictions (e.g. max_length) you can patch the source code of the app, but think twice before doing that, you should have a really good reason for that.

If you want to change verbose_name, you can override label in corresponding form field, no change in model needed.

like image 38
DrTyrsa Avatar answered Sep 24 '22 02:09

DrTyrsa