0

Iam little new to Django and Iam struggling to add column in Django Database.

I was working to create a subcategory for products, but the I want those subcategories to be predefined. That is for example "Fashion" category could have subcategory of 'Men', 'Women', 'Kids'.

I want a table in DB of these subcategories, without having the user or admin panel option to manipulate these field. User can only select article belong to which subcategory.

I go through a few documentation, but could understood much: 1. https://docs.djangoproject.com/en/3.0/howto/custom-model-fields/ 2. Adding fields to an already existing database for Django (version < 1.7)

Please suggest me how to add these predefined table values.

Ankzious
  • 311
  • 3
  • 18

1 Answers1

0

Create subcategories model and model admin then in model admin you can disable change permission like this

Subcategories admin model

def has_change_permission(self, request, obj=None):
    return False

Now you can add,delete and view only permission. User and admin can't change them.