def _handle_created_event(self, **kwargs): amenities = kwargs['attrs'].pop('amenities', None) if amenities: self._amenity_list.extend(Amenity(amenity_type_id=a.keyword_id, is_available=a.is_available) for a in amenities) # django model constructor has pretty smart logic for mass assignment copy_django_model_attrs(self, **kwargs['attrs']) logger.info("{0} has been created".format(self))
def test_copy_django_model_attrs_does_not_copy_pk(test_model): id_field = 1 attrs = {'pk': id_field, 'id': id_field} copy_django_model_attrs(test_model, **attrs) assert id_field != test_model.pk
def test_copy_django_model_attrs_copies_correct_attribute(test_model): title = 'hi' attrs = {'title': title} copy_django_model_attrs(test_model, **attrs) assert title == test_model.title