Opened 11 years ago

Closed 11 years ago

#22033 closed Bug (invalid)

'Model' object has no attribute 'replace'

Reported by: strelnikovdmitrij Owned by: nobody
Component: Utilities Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

..dev/django/django/utils/html.py in escape

def escape(text):

"""
Returns the given text with ampersands, quotes and angle brackets encoded for use in HTML.
"""
return mark_safe(force_text(text).replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;')) ...

escape = allow_lazy(escape, six.text_type)

local vars
Variable Value
text
Error in formatting: coercing to Unicode: need string or buffer, Object found

Change History (3)

comment:1 by Baptiste Mispelon, 11 years ago

Resolution: invalid
Status: newclosed

Hi,

It's hard to say without seeing your models.py but you most likely have an issue with one of your models' __unicode__ method (or __str__ if you're using Python 3).

I'll mark this as invalid. Please provide your models.py if you reopen it.

Thanks.

comment:2 by strelnikovdmitrij, 11 years ago

Resolution: invalid
Status: closednew

models are ok

class AddressManager(models.Manager):

def get_queryset(self):

return QuerySet(self.model, using=self._db)

def address_for_object(self, obj):

object_type = ContentType.objects.get_for_model(obj)
return self.get_queryset().filter(content_typepk=object_type.id, object_id=obj.id)

class Address(models.Model):

objects = AddressManager()

content_type = models.ForeignKey(ContentType, editable=False)
object_id = models.PositiveIntegerField(editable=False)
content_object = generic.GenericForeignKey()

type = models.IntegerField(choices=AddressType.CHOICES)

country = models.CharField(max_length=2, choices=COUNTRIES_SHORT)
city = models.CharField(max_length=60)
city_id = models.IntegerField(default=0, editable=False)
city_part = models.CharField(max_length=60, blank=True)
district = models.CharField(max_length=60, blank=True)
street = models.CharField(max_length=120)
street_number = models.CharField(max_length=10)
house_number = models.CharField(max_length=10, blank=True)
postal_code = models.CharField(max_length=5)

# @property
# def get_street(self):
# return '%s %s' % (self.street, self.get_street_number())
#
# def get_street_number(self):
# if self.house_number:
# return '%s/%s' % (self.street_number, self.house_number)
# return '%s' % self.street_number
#
@classmethod
def types(cls):

return AddressType

#
# def clean(self):
# self.content_object = Company.objects.get(pk=1)

# def unicode(self):
# return self.country

# return smart_text('%s, %s, %s' % (self.street, self.city, self.country))

# def str(self):
# return smart_text('%s, %s, %s' % (self.street, self.city, self.country))

if I create model with data loaded from web (xml, parsed) and save, it return this error on trying to delete via admin.
if I create model with data hardcoded in view and save, it return this error on trying to delete via admin.
If I create model thru admin, with the same values, everything is ok.

fiedls with chars Řeporje, or Smíchov

I did some research.
fields from views - are contains data in unicode with \u09 chars and failed on display
fields created thru admin contains data in str (or unicode) but contains data with \x03..chars

I can edit model, can delete thru shell, everything works. But on trying to delete raise exception, on putting to choices to field, also raise exception

comment:3 by strelnikovdmitrij, 11 years ago

Resolution: invalid
Status: newclosed

I'm stupid, cycling references, sorry guys

Note: See TracTickets for help on using tickets.
Back to Top