def add_schemafield(slug, name, real_name, pretty_name, pretty_name_plural=None, display=True, display_order=0, is_lookup=False, is_filter=False, is_searchable=True, is_charted=False, force=False): # Deliberately blows up if no such schema. schema = Schema.objects.filter(slug=slug)[0] if force: SchemaField.objects.filter(schema=schema, real_name=real_name).delete() field = SchemaField() field.schema = schema # db_attribute model. Choices are: int01-07, text01, # bool01-05, datetime01-04, date01-05, time01-02, # varchar01-05. This value must be unique with respect to the # schema_id. field.real_name = real_name field.name = name field.pretty_name = pretty_name if not pretty_name_plural: if pretty_name.endswith('s'): pretty_name_plural = pretty_name else: pretty_name_plural = pretty_name + 's' field.pretty_name_plural = pretty_name_plural field.display = display field.is_lookup = is_lookup field.is_filter = is_filter field.is_charted = is_charted field.display_order = display_order field.is_searchable = is_searchable field.save()
def add_schemafield(slug, name, real_name, pretty_name, pretty_name_plural=None, display=True, display_order=0, is_lookup=False, is_filter=False, is_searchable=True, is_charted=False, force=False): # Deliberately blows up if no such schema. schema = Schema.objects.filter(slug=slug)[0] if force: SchemaField.objects.filter(schema=schema, real_name=real_name).delete() field = SchemaField() field.schema = schema # db_attribute model. Choices are: int01-07, text01, # bool01-05, datetime01-04, date01-05, time01-02, # varchar01-05. This value must be unique with respect to the # schema_id. field.real_name = real_name field.name = name field.pretty_name = pretty_name if not pretty_name_plural: if pretty_name.endswith('s'): pretty_name_plural = pretty_name else: pretty_name_plural = pretty_name + 's' field.pretty_name_plural = pretty_name_plural field.display = display field.is_lookup = is_lookup field.is_filter = is_filter field.is_charted = is_charted field.display_order = display_order field.is_searchable = is_searchable field.save()
crime_report = Schema() crime_report.indefinite_article = 'a' crime_report.name = "Crime Report" crime_report.plural_name = "Crime Reports" crime_report.slug = 'crimereport' crime_report.min_date = datetime.utcnow() crime_report.last_updated = datetime.utcnow() crime_report.has_newsitem_detail = True crime_report.is_public = True crime_report.save() # custom field officer name officer = SchemaField() officer.schema = crime_report officer.pretty_name = "Reporting Officer's Name" officer.pretty_name_plural = "Reporting Officer's Names" officer.real_name = 'varchar01' officer.name = 'officer' officer.save() # custom field crime type crime_name = SchemaField() crime_name.schema = crime_report crime_name.pretty_name = "Crime Type" crime_name.pretty_plural_name = "Crime Types" crime_name.real_name = "varchar02" crime_name.name = "crime_type" crime_name.save() # custom field crime code crime_code = SchemaField()
crime_report = Schema() crime_report.indefinite_article = 'a' crime_report.name = "Crime Report" crime_report.plural_name = "Crime Reports" crime_report.slug = 'crimereport' crime_report.min_date = datetime.utcnow() crime_report.last_updated = datetime.utcnow() crime_report.has_newsitem_detail = True crime_report.is_public = True crime_report.save() # custom field officer name officer = SchemaField() officer.schema = crime_report officer.pretty_name = "Reporting Officer's Name" officer.pretty_name_plural = "Reporting Officer's Names" officer.real_name = 'varchar01' officer.name = 'officer' officer.save() # custom field crime type crime_name = SchemaField() crime_name.schema = crime_report crime_name.pretty_name = "Crime Type" crime_name.pretty_plural_name = "Crime Types" crime_name.real_name = "varchar02" crime_name.name = "crime_type" crime_name.save() # custom field crime code crime_code = SchemaField()