1 from django
.core
import meta
3 def validate_app(app_label
):
4 mod
= meta
.get_app(app_label
)
5 for klass
in mod
._MODELS
:
8 except AssertionError, e
:
11 def validate_class(klass
):
15 if isinstance(f
, meta
.ManyToManyField
):
16 assert isinstance(f
.rel
, meta
.ManyToMany
), \
17 "ManyToManyField %s should have 'rel' set to a ManyToMany instance." % f
.name
18 # Inline related objects.
19 for related
in opts
.get_followed_related_objects():
20 assert len([f
for f
in related
.opts
.fields
if f
.core
]) > 0, \
21 "At least one field in %s should have core=True, because it's being edited inline by %s." % \
22 (related
.opts
.object_name
, opts
.object_name
)
23 # All related objects.
24 related_apps_seen
= []
25 for related
in opts
.get_all_related_objects():
26 if related
.opts
in related_apps_seen
:
27 assert related
.field
.rel
.related_name
is not None, \
28 "Relationship in field %s.%s needs to set 'related_name' because more than one" \
29 " %s object is referenced in %s." % \
30 (related
.opts
.object_name
, related
.field
.name
, opts
.object_name
, rel_opts
.object_name
)
31 related_apps_seen
.append(related
.opts
)
33 if opts
.admin
is not None:
34 assert opts
.admin
.ordering
or opts
.ordering
, \
35 "%s needs to set 'ordering' on either its 'admin' or its model," \
36 " because it has 'admin' set." % opts
.object_name
38 if __name__
== "__main__":
41 validate_app(sys
.argv
[1])
43 sys
.stderr
.write("Usage: %s [appname]\n" % __file__
)