@Override
public void handleAnnotation(Annotation annotation) {
super.handleAnnotation(annotation);
if (annotation instanceof ModelChoiceFieldProperties) {
ModelChoiceFieldProperties mcfp = (ModelChoiceFieldProperties)annotation;
this.setModel(mcfp.modelClass());
try {
QuerySet<?> qs = null;
if (mcfp.filters().length > 0) {
qs = managers.forClass(getModel()).all();
for(Filter f : mcfp.filters()) {
String[] value = f.value();
if (value != null && value.length > 0) {
if (value != null && value.length == 1) {
qs = qs.filter(f.property(), value[0]);
} else {
qs = qs.filter(f.property(), value);
}
}
if (!"".equals(f.otherProperty())) {
qs = qs.filterByProperty(f.property(), f.otherProperty());
}
if (f.nullCheck()) {
qs = qs.filter(f.property(), null);
}
}
}
if (mcfp.orderby().length > 0) {
qs = qs != null ? qs : managers.forClass(getModel()).all();
qs = qs.orderBy(mcfp.orderby());
}
if (qs != null) setQuerySet(qs);
} catch (ManagerException e) {
// ARGG WHAT TO DO... think of the children