﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
14969	To have a way to modify third part model classes	Marinho Brandão	nobody	"Sometimes we need to modify a model class from a third part application or a Django's contrib, just for a specific project. The most common situations are related to the User, Group and Permission classes, like add new fields, or change __unicode__, etc.

So I wrote this metaclass to allow us to modify a model class from another place of code without really change the original code.

Basically you just inherit '''ModifiedModel''', set a '''Meta''' inner class with '''model = 'application.Model'''' and set attributes with model fields, like below:

""""""
    from django.db import models
    from django.contrib.auth.models import User

    from modify_models import ModifiedModel

    class ModifyingUser(ModifiedModel):
        class Meta:
            model = User
            exclude = ('first_name','last_name',)

        website = models.URLField(blank=True, verify_exists=False)

        def __unicode__(self):
            return '%s - %s'%(self.pk, self.name)
""""""

The code above adds a new field ""website"", excludes ""first_name"" and ""last_name"" and replaces the descriptor __unicode__ in the User model.

In my projects and some of my clients sometimes we need this, so I thought it can be useful for other people and could be part of Django.

I'm attaching a simple Python file to this ticket.

If/when the ticket be approved I can work on documentations and tests and maybe improve the code to be part of the framework (i.e. re-think names)."		closed	Database layer (models, ORM)	dev		wontfix			Unreviewed	0	0	0	0	0	0
