$30 off During Our Annual Pro Sale. View Details »

Everyday Refactoring of a Django Project

Ana Yankova
September 04, 2015

Everyday Refactoring of a Django Project

Ana Yankova

September 04, 2015
Tweet

More Decks by Ana Yankova

Other Decks in Programming

Transcript

  1. !

  2. class Food(models.Model): name = models.CharField(max_length=100) calories = models.Integer(default=0) class FoodBarcode(models.Model):

    barcode = models.CharField(unique=True, max_length=100) food = models.ForeignKey(Food) foodipedia/models.py
  3. " Foodipedia app ! Food Barcode model # Food model

    # ! Barcode Scan model " Barcodes app !
  4. 1 add the new model to Foodipedia 2 Create the

    new app but leave FoodBarcode in Foodipedia
  5. 1 add the new model to Foodipedia 2 3 Create

    the new app but leave FoodBarcode in Foodipedia Create the new app and migrate FoodBarcode and its data
  6. 1 add the new model to Foodipedia 2 3 4

    Create the new app but leave FoodBarcode in Foodipedia Create the new app and refactor but use db_table to avoid schema changes Create the new app and migrate FoodBarcode and its data
  7. class FoodBarcode(models.Model): barcode = models.CharField(unique=True, max_length=100) food = models.ForeignKey('foodipedia.Food') class

    Meta: db_table = u'foodipedia_foodbarcode' class BarcodeScan(models.Model): barcode = models.CharField(unique=True, max_length=100) user = models.ForeignKey(‘accounts.UserProfile') created = models.DateTimeField(auto_now_add=True) barcodes/models.py
  8. class FoodBarcode(models.Model): barcode = models.CharField(unique=True, max_length=100) food = models.ForeignKey('foodipedia.Food') class

    Meta: db_table = u'foodipedia_foodbarcode' class BarcodeScan(models.Model): barcode = models.CharField(unique=True, max_length=100) user = models.ForeignKey(‘accounts.UserProfile') created = models.DateTimeField(auto_now_add=True) barcodes/models.py
  9. class Migration(SchemaMigration): depends_on = (('barcodes', '0001_initial'),) def forwards(self, orm): pass

    foodipedia/migrations/0012_move_foodbarcode.py ./manage.py schemamigration foodipedia --auto
  10. Geek & Poke Font Awesome Practical Object-Oriented Design in Ruby

    by Sandi Metz hilite.me RESOURCES licensed under $ licensed under SIL OFL Stack Overflow: Easiest way to rename a model using Django/South? Two Scoops of Django: Best Practices for Django 1.6 by Daniel Greenfeld & Audrey Roy % % % % % % % %