Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » slight model change makes app unusable [RSS Feed]

#1 Jan. 19, 2011 09:52:20

Santiago C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

slight model change makes app unusable


Hello,

I have got a model MobilePhone that has a producer, such as "alcatel",
a canonical name, such as "b-500 s" and a paraphrase type, such as
"a-341 i". Each instance of MobilePhone is supposed to calculate all
its variants (such as alcatel b-500 s, alcatel b 500 s, alcatel b-500-
s, b-500 s, b 500 s, b-500-s, and so on). This worked perfectly as
long as the producer wasn't a field of its own, but part of the
canonical name. Since I introduced producer names (in order to
simplify the paraphrase types and to allow for variants of producer
names (cf. HP, Hewlett Packard and so on), the app became unusable:
Whenever one wants to see the list of all (461) mobile phones in the
admin interface, the development server becomes very slow and
eventually breaks down with a memory error. Below is the class
MobilePhone. What can I do?

######################################

class MobilePhone(models.Model):

producer = models.ForeignKey(MobilePhoneProducer)
canonical_name = models.CharField(max_length=200)
paraphrase_type = models.CharField(max_length=50, choices=(
('n-127', 'n-127'),
('a-341 i', 'a-341 i'),
('neotouch', 'neotouch'),
))
lexical_variants = models.ManyToManyField(LexicalVariant,
blank=True)
n127_rx = re.compile('^(?P<chars>+)\-(?P<numb>+)$')
a341_i_rx = re.compile('^(?P<chars1>+)\-(?P<numb>+) (?
P<chars2>)$')
neotouch_rx = re.compile('^(?P<model>+)$')

def save(self, *args, **kwargs):
self.canonical_name =
whitespace_normalize(self.canonical_name)
super(MobilePhone, self).save(*args, **kwargs)

def __unicode__(self):
return self.canonical_name

def variants(self):
self.save()
paraphrases = self.paraphrase()
for paraphrase in paraphrases:
paraphrases.append(self.producer.name + ' ' + paraphrase)
for variant in self.lexical_variants.all():
paraphrases.append(variant)
paraphrases.append(self.producer.name + ' ' + variant)
if paraphrases:
return ', '.join(paraphrases)
else:
return '<span style="color:red">(The paraphrase type doesn
\'t seem to match.)</span>'
variants.allow_tags = True

def the_lexical_variants(self):
return ', '.join(self.lexical_variants.all())

the_lexical_variants.short_description = "Lexical variants"

def paraphrase(self):
if self.paraphrase_type == 'n-127':
test = self.n127_rx.search(self.canonical_name)
if test:
chars = test.group('chars')
numb = test.group('numb')
return
elif self.paraphrase_type == 'a-341 i':
test = self.a341_i_rx.search(self.canonical_name)
if test:
chars1 = test.group('chars1')
chars2 = test.group('chars2')
numb = test.group('numb')
return
elif self.paraphrase_type == 'neotouch':
test = self.neotouch_rx.search(self.canonical_name)
if test:
gmodel = test.group('model')
return
return

###############################

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 19, 2011 15:12:49

bruno d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

slight model change makes app unusable


On 19 jan, 10:52, Santiago Caracol <santiago.cara...@gmail.com> wrote:
(snip)
> Whenever one wants to see the list of all (461) mobile phones in the
> admin interface, the development server becomes very slow and
> eventually breaks down with a memory error. Below is the class
> MobilePhone. What can I do?


>     def variants(self):
>         self.save()
>         paraphrases = self.paraphrase()
>         for paraphrase in paraphrases:
>             paraphrases.append(self.producer.name + ' ' + paraphrase)

modifying a list inplace while iterating over it is probably not a
good idea:

source = list("abc")
for item in source:
print item
source.append(item + item)
print source
if raw_input("got it ? ") == "ok":
break


a

got it ? n
b

got it ? n
c

got it ? n
aa

got it ? n
bb

got it ? n
cc

got it ? n
aaaa

got it ? ok


--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » slight model change makes app unusable [RSS Feed]

Board footer

Moderator control

Enjoy the 16th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support