Skip to content

Instantly share code, notes, and snippets.

@ryazwinski
Created August 23, 2013 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryazwinski/6322851 to your computer and use it in GitHub Desktop.
Save ryazwinski/6322851 to your computer and use it in GitHub Desktop.
Django "invalid" model attributes?
class TestModel(models.Model):
my_field = models.CharField(max_length=20)
tm = TestModel.objects.create(my_field='test')
tm.foo = 'bar' # how do I make this fail?
@ryazwinski
Copy link
Author

I expect I somehow need to override setattr but since setattr is used while building the object in the 1st place and when the object is being built it has no attributes... it presents a challenge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment