Commits

Anonymous committed ed64b67

migrate models

Comments (0)

Files changed (2)

dz/migrations/0017_onetoone_organization.py

+# encoding: 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 'Organizacija'
+        db.create_table('dz_organizacija', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+        ))
+        db.send_create_signal('dz', ['Organizacija'])
+
+        # Adding field 'Odbor.organizacija'
+        db.add_column('dz_odbor', 'organizacija', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['dz.Organizacija'], unique=True, null=True), keep_default=False)
+
+        # Adding field 'Skupina.organizacija'
+        db.add_column('dz_skupina', 'organizacija', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['dz.Organizacija'], unique=True, null=True), keep_default=False)
+
+        # Adding field 'Stranka.organizacija'
+        db.add_column('dz_stranka', 'organizacija', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['dz.Organizacija'], unique=True, null=True), keep_default=False)
+
+        # Deleting field 'Pozicija.id_organizacije'
+        db.delete_column('dz_pozicija', 'id_organizacije')
+
+        # Deleting field 'Pozicija.tip_organizacije'
+        db.delete_column('dz_pozicija', 'tip_organizacije_id')
+
+        # Adding field 'Pozicija.organizacija'
+        db.add_column('dz_pozicija', 'organizacija', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['dz.Organizacija'], null=True), keep_default=False)
+
+        # Adding field 'DrzavniZbor.organizacija'
+        db.add_column('dz_drzavnizbor', 'organizacija', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['dz.Organizacija'], unique=True, null=True), keep_default=False)
+
+
+    def backwards(self, orm):
+        
+        # Deleting model 'Organizacija'
+        db.delete_table('dz_organizacija')
+
+        # Deleting field 'Odbor.organizacija'
+        db.delete_column('dz_odbor', 'organizacija_id')
+
+        # Deleting field 'Skupina.organizacija'
+        db.delete_column('dz_skupina', 'organizacija_id')
+
+        # Deleting field 'Stranka.organizacija'
+        db.delete_column('dz_stranka', 'organizacija_id')
+
+        # User chose to not deal with backwards NULL issues for 'Pozicija.id_organizacije'
+        raise RuntimeError("Cannot reverse this migration. 'Pozicija.id_organizacije' and its values cannot be restored.")
+
+        # User chose to not deal with backwards NULL issues for 'Pozicija.tip_organizacije'
+        raise RuntimeError("Cannot reverse this migration. 'Pozicija.tip_organizacije' and its values cannot be restored.")
+
+        # Deleting field 'Pozicija.organizacija'
+        db.delete_column('dz_pozicija', 'organizacija_id')
+
+        # Deleting field 'DrzavniZbor.organizacija'
+        db.delete_column('dz_drzavnizbor', 'organizacija_id')
+
+
+    models = {
+        'dz.clanodbora': {
+            'Meta': {'object_name': 'ClanOdbora'},
+            'do': ('django.db.models.fields.DateField', [], {'blank': 'True'}),
+            'funkcija': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'mandat': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['dz.Mandat']"}),
+            'od': ('django.db.models.fields.DateField', [], {}),
+            'odbor': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['dz.Odbor']"}),
+            'opombe': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'podatki_preverjeni': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'poslanec': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['dz.Funkcija']"})
+        },
+        'dz.clanstranke': {
+            'Meta': {'ordering': "('-do',)", 'object_name': 'ClanStranke'},
+            'do': ('django.db.models.fields.DateField', [], {'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'od': ('django.db.models.fields.DateField', [], {}),
+            'opombe': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'oseba': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['dz.Oseba']"}),
+            'podatki_preverjeni': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'stranka': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['dz.Stranka']", 'null': 'True', 'blank': 'True'})
+        },
+        'dz.drzavnizbor': {
+            'Meta': {'object_name': 'DrzavniZbor'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'mandat': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['dz.Mandat']"}),
+            'organizacija': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['dz.Organizacija']", 'unique': 'True', 'null': 'True'})
+        },
+        'dz.funkcija': {
+            'Meta': {'ordering': "('id',)", 'object_name': 'Funkcija'},
+            'do': ('django.db.models.fields.DateField', [], {'blank': 'True'}),
+            'funkcija': ('django.db.models.fields.CharField', [], {'default': "'poslanec'", 'max_length': '64'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'mandat': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['dz.Mandat']"}),
+            'od': ('django.db.models.fields.DateField', [], {}),
+            'opombe': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'oseba': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['dz.Oseba']"}),
+            'podatki_preverjeni': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
+        },
+        'dz.imestranke': {
+            'Meta': {'ordering': "['-od']", 'object_name': 'ImeStranke'},
+            'do': ('django.db.models.fields.DateField', [], {'default': 'datetime.date(9999, 12, 31)', 'null': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'ime': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'od': ('django.db.models.fields.DateField', [], {'null': 'True'}),
+            'stranka': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['dz.Stranka']"})
+        },
+        'dz.mandat': {
+            'Meta': {'object_name': 'Mandat'},
+            'do': ('django.db.models.fields.DateField', [], {'default': 'datetime.date(9999, 12, 31)', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'od': ('django.db.models.fields.DateField', [], {}),
+            'st': ('django.db.models.fields.IntegerField', [], {})
+        },
+        'dz.odbor': {
+            'Meta': {'object_name': 'Odbor'},
+            'do': ('django.db.models.fields.DateField', [], {'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'ime': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
+            'mandat': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['dz.Mandat']"}),
+            'od': ('django.db.models.fields.DateField', [], {}),
+            'opombe': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'organizacija': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['dz.Organizacija']", 'unique': 'True', 'null': 'True'}),
+            'podatki_preverjeni': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'url': ('django.db.models.fields.URLField', [], {'default': "''", 'max_length': '200', 'blank': 'True'})
+        },
+        'dz.organizacija': {
+            'Meta': {'object_name': 'Organizacija'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+        },
+        'dz.oseba': {
+            'Meta': {'ordering': "('ime', 'priimek')", 'object_name': 'Oseba'},
+            'dan_smrti': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '64', 'blank': 'True'}),
+            'facebook': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'ime': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
+            'opombe': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'podatki_preverjeni': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'priimek': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
+            'rojstni_dan': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
+            'slika': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '96', 'db_index': 'True'}),
+            'spletna_stran': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
+            'twitter': ('django.db.models.fields.CharField', [], {'max_length': '32', 'blank': 'True'}),
+            'vir_slike': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'})
+        },
+        'dz.pozicija': {
+            'Meta': {'object_name': 'Pozicija'},
+            'do': ('django.db.models.fields.DateField', [], {'default': 'datetime.date(9999, 12, 31)', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'od': ('django.db.models.fields.DateField', [], {}),
+            'opombe': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'organizacija': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['dz.Organizacija']", 'null': 'True'}),
+            'oseba': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['dz.Oseba']"}),
+            'podatki_preverjeni': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'tip': ('django.db.models.fields.CharField', [], {'default': "'poslanec'", 'max_length': '64'})
+        },
+        'dz.skupina': {
+            'Meta': {'object_name': 'Skupina'},
+            'do': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'ime': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
+            'mandat': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['dz.Mandat']"}),
+            'od': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
+            'organizacija': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['dz.Organizacija']", 'unique': 'True', 'null': 'True'}),
+            'stranka': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['dz.Stranka']", 'null': 'True', 'blank': 'True'})
+        },
+        'dz.stranka': {
+            'Meta': {'object_name': 'Stranka'},
+            'barva': ('django.db.models.fields.CharField', [], {'max_length': '6', 'blank': 'True'}),
+            'davcna': ('django.db.models.fields.CharField', [], {'max_length': '10', 'blank': 'True'}),
+            'do': ('django.db.models.fields.DateField', [], {'default': 'datetime.date(9999, 12, 31)', 'null': 'True'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '64', 'blank': 'True'}),
+            'facebook': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'ime': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'maticna': ('django.db.models.fields.CharField', [], {'max_length': '10', 'blank': 'True'}),
+            'nastala_iz': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'spremenila_v'", 'blank': 'True', 'to': "orm['dz.Stranka']"}),
+            'od': ('django.db.models.fields.DateField', [], {'null': 'True'}),
+            'okrajsava': ('django.db.models.fields.CharField', [], {'max_length': '16'}),
+            'opombe': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'organizacija': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['dz.Organizacija']", 'unique': 'True', 'null': 'True'}),
+            'podatki_preverjeni': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'spletna_stran': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
+            'twitter': ('django.db.models.fields.CharField', [], {'max_length': '32', 'blank': 'True'})
+        }
+    }
+
+    complete_apps = ['dz']
 from django.db import models
 from django.template.defaultfilters import slugify
 from delajozate.temporal import END_OF_TIME
-from django.contrib.contenttypes.models import ContentType
-from django.contrib.contenttypes import generic
 
 FUNKCIJE = (
 	('poslanec', 'Poslanec/ka'),
 	if date == END_OF_TIME:
 		return None
 	return date
+	
+
+class Organizacija(models.Model):
+	pass
+	
 
 class Oseba(models.Model):
 	ime = models.CharField(max_length=32)
 				self.slug = "%s-%d" % (slug, count)
 				count += 1
 		super(Oseba, self).save(*args, **kwargs)
+	
 
 class Stranka(models.Model):
 	# kako modelirat kontinuiteto stranke, kadar se preimenuje?
 	facebook = models.URLField(blank=True)
 	podatki_preverjeni = models.BooleanField(default=False)
 	opombe = models.TextField(blank=True)
+	organizacija = models.OneToOneField(Organizacija, null=True)
+	
+	def save(self, *args, **kwargs):
+		if not self.organizacija_id:
+			self.organizacija = Organizacija.objects.create()
+		super(Odbor, self).save(*args, **kwargs)
 	
 	class Meta:
 		verbose_name_plural = u'Stranke'
 	
 	def __unicode__(self):
 		return u'%s (%s)%s' % (self.ime, self.okrajsava, self.do != END_OF_TIME and u'\u271d' or u'')
+	
 
 class ImeStranke(models.Model):
 	stranka = models.ForeignKey(Stranka)
 	class Meta:
 		ordering = [ '-od']
 		verbose_name_plural = u'Imena strank'
+	
 
 class Mandat(models.Model):
 	st = models.IntegerField() # Kateri mandat
 	
 	def __unicode__(self):
 		return unicode(self.st)
+	
 
 class Skupina(models.Model): # Poslanska
 	ime = models.CharField(max_length=64)
 	od = models.DateField(null=True, blank=True)
 	do = models.DateField(null=True, blank=True)
 	mandat = models.ForeignKey(Mandat)
+	organizacija = models.OneToOneField(Organizacija, null=True)
+	
+	def save(self, *args, **kwargs):
+		if not self.organizacija_id:
+			self.organizacija = Organizacija.objects.create()
+		super(Odbor, self).save(*args, **kwargs)
 	
 	class Meta:
 		verbose_name_plural = u'Skupine'
+	
 
 class DrzavniZbor(models.Model):
 	mandat = models.ForeignKey(Mandat)
+	organizacija = models.OneToOneField(Organizacija, null=True)
+	
+	def save(self, *args, **kwargs):
+		if not self.organizacija_id:
+			self.organizacija = Organizacija.objects.create()
+		super(Odbor, self).save(*args, **kwargs)
 	
 	class Meta:
 		verbose_name = u'Državni Zbor'
 		verbose_name_plural = u'Državni Zbori'
+	
 
 class Odbor(models.Model):
 	ime = models.CharField(max_length=500)
 	do = models.DateField(blank=True)
 	podatki_preverjeni = models.BooleanField(default=False)
 	opombe = models.TextField(blank=True)
+	organizacija = models.OneToOneField(Organizacija, null=True)
+	
+	def save(self, *args, **kwargs):
+		if not self.organizacija_id:
+			self.organizacija = Organizacija.objects.create()
+		super(Odbor, self).save(*args, **kwargs)
 	
 	class Meta:
 		verbose_name_plural = u'Odbori'
 	
 	def __unicode__(self):
 		return '%s (%s)' % (self.ime, self.mandat)
+	
 
 class Funkcija(models.Model):
 	oseba = models.ForeignKey(Oseba)
 	
 	def __unicode__(self):
 		return u'%s (%s)' % (self.oseba, self.mandat)
+	
 
 class ClanStranke(models.Model):
 	oseba = models.ForeignKey(Oseba)
 		verbose_name = u'Član stranke'
 		verbose_name_plural = u'Člani strank'
 		ordering = ('-do',)
+	
 
 class ClanOdbora(models.Model):
 	odbor = models.ForeignKey(Odbor)
 
 class Pozicija(models.Model):
 	oseba = models.ForeignKey(Oseba)
-	
-	tip_organizacije = models.ForeignKey(ContentType)
-	id_organizacije = models.PositiveIntegerField()
-	organizacija = generic.GenericForeignKey('tip_organizacije', 'id_organizacije')
-	
+	organizacija = models.ForeignKey(Organizacija, null=True)
 	tip = models.CharField(max_length=64, default='poslanec', choices=FUNKCIJE)
 	od = models.DateField()
-	do = models.DateField(blank=True)
+	do = models.DateField(blank=True, default=END_OF_TIME)
 	podatki_preverjeni = models.BooleanField(default=False)
 	opombe = models.TextField(blank=True)
 	
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.