|
148 | 148 | } |
149 | 149 |
|
150 | 150 |
|
| 151 | +known_missing_person_records = [ |
| 152 | + (3150, "Steve Kille"), |
| 153 | +] |
| 154 | + |
151 | 155 | def forward(apps,schema_editor): |
152 | 156 |
|
153 | 157 | Email=apps.get_model('person','Email') |
| 158 | + Person = apps.get_model('person', 'Person') |
| 159 | + |
| 160 | + for id, name in known_missing_person_records: |
| 161 | + if not Person.objects.filter(id=id).exists(): |
| 162 | + Person.objects.create(id=id, name=name, ascii=name) |
154 | 163 |
|
155 | 164 | # Sanity check |
156 | | - for addr in new_addresses.keys(): |
| 165 | + for addr, id in new_addresses.items(): |
157 | 166 | if Email.objects.filter(address__iexact=addr).exists(): |
158 | 167 | raise Exception("%s already exists in the Email table"%addr) |
| 168 | + if not Person.objects.filter(id=id).exists(): |
| 169 | + raise Exception("ID #%s is missing in the Person table"%id) |
159 | 170 |
|
160 | 171 | for addr in new_addresses.keys(): |
161 | 172 | Email.objects.create(address=addr,person_id=new_addresses[addr],active=False,primary=False) |
162 | 173 |
|
163 | 174 | def reverse(apps,schema_editor): |
164 | 175 | Email=apps.get_model('person','Email') |
| 176 | + Person = apps.get_model('person', 'Person') |
165 | 177 | #Person=apps.get_model('person','Person') |
166 | 178 | #print "new_addresses = {" |
167 | 179 | #for addr in sorted(new_addresses.keys()): |
168 | 180 | # print "'%s': %s, # %s"%(addr,new_addresses[addr],Person.objects.get(pk=new_addresses[addr]).name) |
169 | 181 | #print "}" |
170 | 182 | Email.objects.filter(address__in=new_addresses.keys()).delete() |
| 183 | + Person.objects.filter(id__in=[ id for id,name in known_missing_person_records ]).delete() |
171 | 184 |
|
172 | 185 | class Migration(migrations.Migration): |
173 | 186 |
|
|
0 commit comments