Ticket #1745: m2m_requires_pk_val.patch
File m2m_requires_pk_val.patch, 1.3 KB (added by , 19 years ago) |
---|
-
django/db/models/fields/related.py
239 239 self.join_table = join_table 240 240 self.source_col_name = source_col_name 241 241 self.target_col_name = target_col_name 242 if instance: 243 self._pk_val = self.instance._get_pk_val() 242 self._pk_val = self.instance._get_pk_val() 243 if self._pk_val is None: 244 raise ValueError("%r instance needs to have a primary key value before a many-to-many relationship can be used." % model) 244 245 245 246 def get_query_set(self): 246 247 return superclass.get_query_set(self).filter(**(self.core_filters)) -
tests/modeltests/many_to_many/models.py
110 110 >>> a2.delete() 111 111 >>> Article.objects.all() 112 112 [Django lets you build Web apps easily] 113 >>> p 1.article_set.all()114 [ Django lets you build Web apps easily]113 >>> p2.article_set.all() 114 [] 115 115 116 116 # Adding via the 'other' end of an m2m 117 117 >>> a4 = Article(headline='NASA finds intelligent life on Earth')