Hi Colin,

Thanks for getting back

On Monday, August 18, 2014 4:58:20 PM UTC+2, Collin Anderson wrote:
>
> The goal is to have "API methods that let you introspect the fields and 
> relations that exist on a model", right? Why go though the trouble of 
> finding the one specific type for each field (that we'll never be able to 
> change later)? Why have a get_fields() method with an ever-growing number 
> of kwargs?
>
> I want all "related" fields. Easy:
> (f for f in _meta.fields if hasattr(f, 'rel'))
>

> I want all read-only fields. Easy:
> (f for f in _meta.fields if not f.editable)
>
> I want all fields that can be edited through a form. Something like:
> (f for f in _meta.fields if hasattr(f, 'formfield'))
>
> I want all "local" fields (not that you should care). Easy:
> (f for f in _meta.fields if f.model == _meta.model)
>
> I want all fields that have an actual column in the database. Something 
> like
> (f for f in _meta.fields if f.db_type())
>
> I want all fields that function like a ManyToMany. Easy:
> (f for f in _meta.fields if f.get_internal_type() == 'ManyToManyField')
>
> I want all fields that have ForeignKey.to_field pointing to them. 
> Something like:
> set(_meta.get_field(fname) for rel in _meta.related for fname in 
> rel.to_fields)
>

Ha! I wish it was so easy :( unfortunately there are quite a bit of edge 
cases that need to be take into consideration. For example:
field.rel: many fields have a rel, but point to None. Also there are cases 
when rel points to a swapped model. In this case we need to do some more 
work.
ManyToMany: do we really want to hard-code this? or do we want to have an 
internal component handle it for us. What happens when NoSQL comes to 
Django (I really believe in this..).
get_fields() also gives us the possibility of changing internals without 
necessarily affecting behaviour. It's that layer of abstraction that I feel 
is needed.
Said this, if we can simplify it and still avoid duplication and provide 
the level of functionality it's giving us now, then that would be great.
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/12ee8db0-dd85-4410-b402-ce9e343be744%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to