Minor changes to models and importer

This commit is contained in:
tec
2014-11-05 22:37:32 +00:00
parent 258e1faf0f
commit e1fef479af
2 changed files with 14 additions and 17 deletions

View File

@@ -99,20 +99,17 @@ def import_venues(delete=False):
sql = """SELECT `venue`, `threephasepower` FROM `eventdetails` WHERE `venue` IS NOT NULL"""
cursor.execute(sql)
for row in cursor.fetchall():
object, created = models.Venue.objects.get_or_create(name__iexact=row[0])
if created:
print("Created: " + object.__str__())
with transaction.atomic(), reversion.create_revision():
object.three_phase_available = row[1]
object.save()
else:
if not object.three_phase_available and row[1] == 1:
print("Updating: " + object.__str__())
with transaction.atomic(), reversion.create_revision():
object.three_phase_available = row[1]
object.save()
else:
print("Found: " + object.__str__())
print("Searching for %s", row[0])
object = models.Venue.objects.get(name__iexact=row[0])
if object:
if not object.three_phase_available and row[1]:
with transaction.atomic(), reversion.create_revision():
object.three_phase_available = row[1]
object.save()
else:
with transaction.atomic(), reversion.create_revision():
object = models.Venue(name=row[0], three_phase_available=row[1])
object.save()
def main():
# import_people()

View File

@@ -88,8 +88,8 @@ class Venue(models.Model, RevisionMixin):
def __str__(self):
string = self.name
if len(self.notes) > 0:
string += "*"
if self.notes and len(self.notes) > 0:
string += "*"
return string
@@ -163,4 +163,4 @@ class EventCrew(models.Model):
rig = models.BooleanField(default=False)
run = models.BooleanField(default=False)
derig = models.BooleanField(default=False)
notes = models.TextField(blank=True, null=True)
notes = models.TextField(blank=True, null=True)