Login

Tag "change"

Snippet List

Modifying the fields of a third/existing model class

You can extend the class **ModifiedModel** to set new fields, replace existing or exclude any fields from a model class without patch or change the original code. **my_app/models.py** from django.db import models class CustomerType(models.Model): name = models.CharField(max_length=50) def __unicode__(self): return self.name class Customer(models.Model): name = models.CharField(max_length=50) type = models.ForeignKey('CustomerType') is_active = models.BooleanField(default=True, blank=True) employer = models.CharField(max_length=100) def __unicode__(self): return self.name **another_app/models.py** from django.db import models from django.contrib.auth.models import User from this_snippet import ModifiedModel class City(models.Model): name = models.CharField(max_length=50) def __unicode__(self): return self.name class HelperCustomerType(ModifiedModel): class Meta: model = 'my_app.CustomerType' description = models.TextField() class HelperCustomer(ModifiedModel): class Meta: model = 'my_app.Customer' exclude = ('employer',) type = models.CharField(max_length=50) # Replaced address = models.CharField(max_length=100) city = models.ForeignKey(City) def __unicode__(self): return '%s - %s'%(self.pk, self.name) class HelperUser(ModifiedModel): class Meta: model = User website = models.URLField(blank=True, verify_exists=False)

  • fields
  • model
  • helper
  • change
Read More

Admin change language

This snippet adds a select language drop down menu in the admin bar (just after Documentation link). For this approach it's necessary to copy from admin templates the admin/base.html to the project templates (keeping the admin directory), changing just line 25 ad shown. Then it's necessary to create specified admin/change_language.html template.

  • admin
  • language
  • change
Read More

chdjango

This is a convenient script for those working with different branches of Django. Place all of your branches in `~/django` (e.g., `~/django/newforms-admin`, `~/django/trunk`) and you're ready to quickly change between them. For example: `chdjango.py trunk`.

  • django
  • path
  • change
  • chdjango
  • branches
  • pth
  • site-packages
Read More

4 snippets posted so far.