Commits

Viorel Stirbu committed e40ed37

renamed hit date field

  • Participants
  • Parent commits 641266b

Comments (0)

Files changed (6)

atexpc/atex_web/migrations/0005_product_hits.py

-# -*- coding: utf-8 -*-
-import datetime
-from south.db import db
-from south.v2 import SchemaMigration
-from django.db import models
-
-
-class Migration(SchemaMigration):
-
-    def forwards(self, orm):
-        # Adding model 'Hit'
-        db.create_table('atex_web_hit', (
-            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
-            ('product', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['atex_web.Product'])),
-            ('hit_date', self.gf('django.db.models.fields.DateField')()),
-            ('count', self.gf('django.db.models.fields.IntegerField')()),
-        ))
-        db.send_create_signal('atex_web', ['Hit'])
-
-
-    def backwards(self, orm):
-        # Deleting model 'Hit'
-        db.delete_table('atex_web_hit')
-
-
-    models = {
-        'atex_web.dropbox': {
-            'Meta': {'object_name': 'Dropbox'},
-            'app_key': ('django.db.models.fields.CharField', [], {'max_length': '64', 'primary_key': 'True'}),
-            'delta_cursor': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'})
-        },
-        'atex_web.hit': {
-            'Meta': {'object_name': 'Hit'},
-            'count': ('django.db.models.fields.IntegerField', [], {}),
-            'hit_date': ('django.db.models.fields.DateField', [], {}),
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['atex_web.Product']"})
-        },
-        'atex_web.image': {
-            'Meta': {'object_name': 'Image'},
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'image': ('sorl.thumbnail.fields.ImageField', [], {'max_length': '255'}),
-            'path': ('django.db.models.fields.CharField', [], {'max_length': '128', 'db_index': 'True'}),
-            'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['atex_web.Product']", 'null': 'True', 'on_delete': 'models.SET_NULL'})
-        },
-        'atex_web.product': {
-            'Meta': {'object_name': 'Product'},
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'model': ('django.db.models.fields.CharField', [], {'max_length': '64'})
-        }
-    }
-
-    complete_apps = ['atex_web']

atexpc/atex_web/migrations/0005_product_info.py

+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding field 'Product.ancora_id'
+        db.add_column('atex_web_product', 'ancora_id',
+                      self.gf('django.db.models.fields.IntegerField')(null=True),
+                      keep_default=False)
+
+        # Adding unique constraint on 'Product', fields ['model']
+        db.create_unique('atex_web_product', ['model'])
+
+
+    def backwards(self, orm):
+        # Removing unique constraint on 'Product', fields ['model']
+        db.delete_unique('atex_web_product', ['model'])
+
+        # Deleting field 'Product.ancora_id'
+        db.delete_column('atex_web_product', 'ancora_id')
+
+
+    models = {
+        'atex_web.dropbox': {
+            'Meta': {'object_name': 'Dropbox'},
+            'app_key': ('django.db.models.fields.CharField', [], {'max_length': '64', 'primary_key': 'True'}),
+            'delta_cursor': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'})
+        },
+        'atex_web.image': {
+            'Meta': {'object_name': 'Image'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'image': ('sorl.thumbnail.fields.ImageField', [], {'max_length': '255'}),
+            'path': ('django.db.models.fields.CharField', [], {'max_length': '128', 'db_index': 'True'}),
+            'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['atex_web.Product']", 'null': 'True', 'on_delete': 'models.SET_NULL'})
+        },
+        'atex_web.product': {
+            'Meta': {'object_name': 'Product'},
+            'ancora_id': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64'})
+        }
+    }
+
+    complete_apps = ['atex_web']

atexpc/atex_web/migrations/0006_product_ancora_id.py

-# -*- coding: utf-8 -*-
-import datetime
-from south.db import db
-from south.v2 import SchemaMigration
-from django.db import models
-
-
-class Migration(SchemaMigration):
-
-    def forwards(self, orm):
-        # Adding field 'Product.ancora_id'
-        db.add_column('atex_web_product', 'ancora_id',
-                      self.gf('django.db.models.fields.IntegerField')(null=True),
-                      keep_default=False)
-
-
-    def backwards(self, orm):
-        # Deleting field 'Product.ancora_id'
-        db.delete_column('atex_web_product', 'ancora_id')
-
-
-    models = {
-        'atex_web.dropbox': {
-            'Meta': {'object_name': 'Dropbox'},
-            'app_key': ('django.db.models.fields.CharField', [], {'max_length': '64', 'primary_key': 'True'}),
-            'delta_cursor': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'})
-        },
-        'atex_web.hit': {
-            'Meta': {'object_name': 'Hit'},
-            'count': ('django.db.models.fields.IntegerField', [], {}),
-            'hit_date': ('django.db.models.fields.DateField', [], {}),
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['atex_web.Product']"})
-        },
-        'atex_web.image': {
-            'Meta': {'object_name': 'Image'},
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'image': ('sorl.thumbnail.fields.ImageField', [], {'max_length': '255'}),
-            'path': ('django.db.models.fields.CharField', [], {'max_length': '128', 'db_index': 'True'}),
-            'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['atex_web.Product']", 'null': 'True', 'on_delete': 'models.SET_NULL'})
-        },
-        'atex_web.product': {
-            'Meta': {'object_name': 'Product'},
-            'ancora_id': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'model': ('django.db.models.fields.CharField', [], {'max_length': '64'})
-        }
-    }
-
-    complete_apps = ['atex_web']

atexpc/atex_web/migrations/0006_product_hits.py

+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding model 'Hit'
+        db.create_table('atex_web_hit', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('product', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['atex_web.Product'])),
+            ('count', self.gf('django.db.models.fields.IntegerField')()),
+            ('date', self.gf('django.db.models.fields.DateField')()),
+        ))
+        db.send_create_signal('atex_web', ['Hit'])
+
+
+    def backwards(self, orm):
+        # Deleting model 'Hit'
+        db.delete_table('atex_web_hit')
+
+
+    models = {
+        'atex_web.dropbox': {
+            'Meta': {'object_name': 'Dropbox'},
+            'app_key': ('django.db.models.fields.CharField', [], {'max_length': '64', 'primary_key': 'True'}),
+            'delta_cursor': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'})
+        },
+        'atex_web.hit': {
+            'Meta': {'object_name': 'Hit'},
+            'count': ('django.db.models.fields.IntegerField', [], {}),
+            'date': ('django.db.models.fields.DateField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['atex_web.Product']"})
+        },
+        'atex_web.image': {
+            'Meta': {'object_name': 'Image'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'image': ('sorl.thumbnail.fields.ImageField', [], {'max_length': '255'}),
+            'path': ('django.db.models.fields.CharField', [], {'max_length': '128', 'db_index': 'True'}),
+            'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['atex_web.Product']", 'null': 'True', 'on_delete': 'models.SET_NULL'})
+        },
+        'atex_web.product': {
+            'Meta': {'object_name': 'Product'},
+            'ancora_id': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64'})
+        }
+    }
+
+    complete_apps = ['atex_web']

atexpc/atex_web/migrations/0007_product_model_unique.py

-# -*- coding: utf-8 -*-
-import datetime
-from south.db import db
-from south.v2 import SchemaMigration
-from django.db import models
-
-
-class Migration(SchemaMigration):
-
-    def forwards(self, orm):
-        # Adding unique constraint on 'Product', fields ['model']
-        db.create_unique('atex_web_product', ['model'])
-
-
-    def backwards(self, orm):
-        # Removing unique constraint on 'Product', fields ['model']
-        db.delete_unique('atex_web_product', ['model'])
-
-
-    models = {
-        'atex_web.dropbox': {
-            'Meta': {'object_name': 'Dropbox'},
-            'app_key': ('django.db.models.fields.CharField', [], {'max_length': '64', 'primary_key': 'True'}),
-            'delta_cursor': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'})
-        },
-        'atex_web.hit': {
-            'Meta': {'object_name': 'Hit'},
-            'count': ('django.db.models.fields.IntegerField', [], {}),
-            'hit_date': ('django.db.models.fields.DateField', [], {}),
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['atex_web.Product']"})
-        },
-        'atex_web.image': {
-            'Meta': {'object_name': 'Image'},
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'image': ('sorl.thumbnail.fields.ImageField', [], {'max_length': '255'}),
-            'path': ('django.db.models.fields.CharField', [], {'max_length': '128', 'db_index': 'True'}),
-            'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['atex_web.Product']", 'null': 'True', 'on_delete': 'models.SET_NULL'})
-        },
-        'atex_web.product': {
-            'Meta': {'object_name': 'Product'},
-            'ancora_id': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'model': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64'})
-        }
-    }
-
-    complete_apps = ['atex_web']

atexpc/atex_web/models.py

     def get_top_hits(self, limit=5):
         one_month_ago = datetime.now(pytz.utc).date() - timedelta(days=30)
         return (self.filter(hit__count__gte=1,
-                            hit__hit_date__gte=one_month_ago)
+                            hit__date__gte=one_month_ago)
                     .annotate(month_count=models.Sum('hit__count'))
                     .order_by('-month_count')[:limit])
 
     def hit(self):
         today = datetime.now(pytz.utc).date()
         hit_info = {'count': 1}
-        hit, created = Hit.objects.get_or_create(product=self, hit_date=today,
+        hit, created = Hit.objects.get_or_create(product=self, date=today,
                                                  defaults=hit_info)
         if not created:
             hit.count = models.F('count') + 1
 
 
 class Hit(models.Model):
-    product = models.ForeignKey(Product, unique_for_date="hit_date")
+    product = models.ForeignKey(Product, unique_for_date="date")
     count = models.IntegerField()
-    hit_date = models.DateField()
+    date = models.DateField()
 
 
 class AncoraBackend(object):