select_related across many to many fields in django or how do i access many to many fields using .all() -


I am writing data migrations using south ... but select question_relation to get many people using Field for

The documentation specifies that select_related can be used for fields with relationships of foreign use ... I can not understand that 'work with many areas right'?

In my area empty = zero but the documentation says that you can still call select_related ('field_name') and it will drag related relationships. So far when I try to do this below ...

listing a query in the query group

  RealEstateListing.objects.all () am: listing_type_slug_url = slugify (listing.listing_type.name) sub_type = orm.SubType.objects.get (slug_url = listing_type_slug_url) pricing_option = PricingOption.objects.get (name = listing.pricing_option.name) lt = orm.Listing (listing_type = sub_type.parent, sub_type = sub_type, expiration_date = listing.expiration_date, title = listing.title, slug_url = listing.slug_url, Description = listing.description, contact_person = listing.contact_person, secondary_contact = listing.secondary_contact, address = listing.address , Location = list location, value = listing. Value, pric ing_option = pricing_option, display_picture = listing.display_picture, image_gallery = listing.image_gallery, DATE_ADDED = listing.date_added, status = listing.status, featured_on_homepage = listing.featured_on_homepage,) lt.save () does lt.features.clear (), Then list property_features: property_features = listing.property_features.all () and: property_features = no property_features if: for property_features feet: ft_ = Feature.objects.get (name = ft.name) lt.features.add (ft_)  

I get an error stating that it can not resolve the properties of the area ... Available fields are only id & amp; Name ... It seems that the relationship is not pulling.

My second question is, can not we use select_related to select many options in many areas?

- ------------------------------------------ ---- edit --- -------------------------------------

I removed the context of the South Fake orm which I was using to migrate data.

I basically am with the above code, an old listed object data from the old to all the RealEstateListings object to loop

< / Div>

It is very impossible to debug your code because it seems That is failing in any method you use. My guess is that you are doing objects. Failure (property_facture = ...) is expected to replace property_features with a property that you can not do because it is written as a keyword argument.

It also seems that you have misused the use of select_related, it is used to avoid additional questions to reach purely related objects. I am not sure about the M2M field, but they are not similar to the FK, so do not react to them.

Edit:

Therefore RealEstateListing is called an M2M property_system

If this statement is not good, then close it first:

  If listing.property_features: property_features = listing.property_features.all () else: property_features = none if property_features:  

after all RealEstateListing a M2M always Will be true as isting.property_features will return a django.db.models.fields.related.ManyRelatedManager object which will evaluate on the right. If there was no M2M field on the listing, you would get an attribute error instead. This is not the error you received, however, you should change the code above to your:

  property_features = listing.property_features.all () if property_features:  

This will do the same, when there is no property / property, then the properties on the object will be empty function variable.

Now for the real error, I should say that whatever you have written can cause that error as if you do something like this before you get such an error. / P>

  listing.objects.filter (property_features = x)  

Posting a full trade back will help identify where the problem occurs.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -