-1

I added a field to auth.Group model with the add_to_class method like said here:

Add extra Fields to Django to Django Auth Groups

I added this in models.py:

Group.add_to_class('type', models.CharField(max_length=100))

When I did that, it looks like the field has been added to the model class but not as a db field... So when I try to reach the admin page of Group, it says my new field does not exist. After some research it looks like adding field to auth.Group with this method is not really good as well.

What I want to do is delete the new field I added but I don't know how. From what I understand from this answer:

Delete field from standard Django model

I have to delete the field from the Model._meta.fields list but I don't know how.

Community
  • 1
  • 1
dguay
  • 1,635
  • 15
  • 24
  • 2
    Just leave out the code that added it in the first place. – knbk Jul 24 '14 at 15:34
  • "when I try to reach the admin page of Group, it says my new field does not exist" ...this is because the schema of the underlying database has not changed. You need to use South or the new migrations feature in Django 1.7 to actually add the field to the database and not just the model class – Anentropic Jul 24 '14 at 15:44
  • if you delete the code you added `Group.add_to_class...` then the new field will no longer exist on your model class – Anentropic Jul 24 '14 at 15:46
  • I deleted the code and then sync the db with south and restart server with supervisor but the field is always there. It looks like I added the same field multiple times... Check my question again I edited. For your first comment, south doesn't track the change: http://stackoverflow.com/questions/24180021/python-south-not-picking-up-changes-made-in-add-to-class-method – dguay Jul 24 '14 at 15:49
  • Is there any way to delete a field from Model._meta.fields? – dguay Jul 25 '14 at 15:41

1 Answers1

0

Try this:

for field in ModelName._meta.fields:
  if field.name == 'unwanted_field_name':
    ModelName._meta.fields.remove(field)
GAEfan
  • 11,244
  • 2
  • 17
  • 33