djangosnippets.org: Latest snippets tagged with 'metaprogramming'http://djangosnippets.org/tags/metaprogramming/2019-08-17T01:45:31.434454-05:00Model mixin to return all field data in a dictionary
2019-08-17T01:45:31.434454-05:00rixxhttp://djangosnippets.org/snippets/10678/<p>Get all field data, e.g. for an export.</p>
Freely redistributableModelMixin
2010-11-04T10:53:02.482343-05:00eallikhttp://djangosnippets.org/snippets/2249/<p>Enables convenient adding of fields, methods and properties to Django models.
</p>
<p>Instead of:
</p>
<pre><code>User.add_to_class('foo', models.CharField(...)
User.add_to_class('bar', models.IntegerField(...)
</code></pre><p>you can write:
</p>
<pre><code>class UserMixin(ModelMixin):
model = User
foo = models.CharField(...)
bar = models.IntegerField(...)
</code></pre>
Freely redistributable