i'm writing a data migration using south... but the question refers to the use of select_related to retrieve many to many fields.
the documentation specifies that select_related can be used for fields with relationships using ForeignKey ... i can't fathom it wont' work with ManyToMany fields right?
my field have blank=null but the documentation says you can still call select_related('field_name') and it will pull the relevant relationships. yet when i'm trying to do this below...
where listing is a item in a queryset
for listing in RealEstateListing.objects.all():
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=listing.location,
price=listing.price,
pricing_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()
lt.features.clear()
if listing.property_features:
property_features = listing.property_features.all()
else:
property_features = None
if property_features:
for ft in property_features:
ft_ = Feature.objects.get(name=ft.name)
lt.features.add(ft_)
i get an error telling me that it cannot resolve the field property_features ... the available fields are only id & name... it seems its not pulling the relationships.
my other question is if we can't use select_related to access many to many fields what is the alternative?
------------------------------------------------EDIT----------------------------------------
i removed the reference to south's fake orm which i was using to do the data migration.
what i'm basically doing with the code above is taking all RealEstateListings objects then in a for loop creating a new Listing object with the data from the old RealEstateListings
the last part is where i have the problem and gives me the error above with the many to many field property_features from the old RealEstateListing model