Slide 1

Slide 1 text

EVERYDAY REFACTORING OF A DJANGO PROJECT

Slide 2

Slide 2 text

We all want to build new features

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

The fast pace is fun but…

Slide 5

Slide 5 text

Haste is waste

Slide 6

Slide 6 text

What about technical debt?

Slide 7

Slide 7 text

If it ain't broke, don't fix it. Rewrite the whole codebase!

Slide 8

Slide 8 text

Test it!

Slide 9

Slide 9 text

The later the change the higher the costs

Slide 10

Slide 10 text

Everyday refactoring

Slide 11

Slide 11 text

Usable TRUE Transparent Reasonable Exemplary

Slide 12

Slide 12 text

Exemplary

Slide 13

Slide 13 text

!

Slide 14

Slide 14 text

class BarcodeScan(models.Model): barcode = models.CharField(unique=True, max_length=100) user = models.ForeignKey(‘accounts.UserProfile') created = models.DateTimeField(auto_now_add=True)

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

" Foodipedia app ! Food Barcode model # Food model # ! Barcode Scan model " Barcodes app !

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

1 add the new model to Foodipedia

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

class Migration(DataMigration): def forwards(self, orm): orm['contenttypes.contenttype'].objects.filter( app_label='foodipedia', model='foodbarcode', ).update(app_label='barcodes') barcodes/migrations/0001_initial.py ./manage.py datamigration barcodes 0001_initial --frozen contenttypes

Slide 25

Slide 25 text

class Migration(SchemaMigration): depends_on = (('barcodes', '0001_initial'),) def forwards(self, orm): pass foodipedia/migrations/0012_move_foodbarcode.py ./manage.py schemamigration foodipedia --auto

Slide 26

Slide 26 text

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 % % % % % % % %

Slide 27

Slide 27 text

[email protected] anah @anhristova & ' (