Search Results

Search found 4 results on 1 pages for 'rh0dium'.

Page 1/1 | 1 

  • Django Querysets -- need a less expensive way to do this..

    - by rh0dium
    Hi all, I have a problem with some code and I believe it is because of the expense of the queryset. I am looking for a much less expensive (in terms of time) way to to this.. log.info("Getting Users") employees = Employee.objects.filter(is_active = True) log.info("Have Users") if opt.supervisor: if opt.hierarchical: people = getSubs(employees, " ".join(args)) else: people = employees.filter(supervisor__name__icontains = " ".join(args)) else: log.info("Filtering Users") people = employees.filter(name__icontains = " ".join(args)) | \ employees.filter(unix_accounts__username__icontains = " ".join(args)) log.info("Filtered Users") log.info("Processing data") np = [] for person in people: unix, p4, bugz = "No", "No", "No" if len(person.unix_accounts.all()): unix = "Yes" if len(person.perforce_accounts.all()): p4 = "Yes" if len(person.bugzilla_accounts.all()): bugz = "Yes" if person.cell_phone != "": exphone = fixphone(person.cell_phone) elif person.other_phone != "": exphone = fixphone(person.other_phone) else: exphone = "" np.append({ 'name':person.name, 'office_phone': fixphone(person.office_phone), 'position': person.position, 'location': person.location.description, 'email': person.email, 'functional_area': person.functional_area.name, 'department': person.department.name, 'supervisor': person.supervisor.name, 'unix': unix, 'perforce': p4, 'bugzilla':bugz, 'cell_phone': fixphone(exphone), 'fax': fixphone(person.fax), 'last_update': person.last_update.ctime() }) log.info("Have data") Now this results in a log which looks like this.. 19:00:55 INFO phone phone Getting Users 19:00:57 INFO phone phone Have Users 19:00:57 INFO phone phone Processing data 19:01:30 INFO phone phone Have data As you can see it's taking over 30 seconds to simply iterate over the data. That is way too expensive. Can someone clue me into a more efficient way to do this. I thought that if I did the first filter that would make things easier but seems to have no effect. I'm at a loss on this one. Thanks To be clear this is about 1500 employees -- Not too many!!

    Read the article

  • Django Database design -- Is this a good stragety for overriding defaults

    - by rh0dium
    Hi SO's I have a question on good database design practices and I would like to leverage you guys for pointers. The project started out simple. Hey we have a bunch of questions we want answered for every project (no problem) Which turned into... Hey we have so many questions can we group them into sections (yup we can do that) Which lead into.. Can we weight these questions and I don't really want some of these questions for my project (Yes but we are getting difficult) And then I'm thinking they will want to have each section have it's own weight.. Requirements So there's the requirements - For n number of project Allow a admin member the ability select the questions for a project Allow the admin member to re-weigh or use the default weights for the questions Allow the admin member to re-weight the sections Allow team members to answer the questions. So here is what I came up with. Please feel free to comment and provide better examples models.py from django.db import models from django.contrib.sites.models import Site from django.conf import settings class Section(models.Model): """ This describes the various sections for a checklist: """ name = models.CharField(max_length=64) description = models.TextField() class Question(models.Model): """ This simply provides a simple way to list out the questions. """ question = models.CharField(max_length=255) answer_type = models.CharField(max_length=16) description = models.TextField() section = models.ForeignKey(Section) class ProjectQuestion(models.Model): """ These are the questions relevant to the project """ question = models.ForeignKey(Question) answer = models.CharField(max_length=255) required = models.BooleanField(default=True) weight = models.FloatField(default = XXX) class Project(models.Model): """ Here is where we want to gather our questions """ questions = models.ManyToManyField(ProjectQuestion) Immediate questions: - When I start a project - any ideas on how to "pre-populate" the questions (and ultimately the weights) for the project? - Is there a generally accepted method for doing this process that I am missing? Basically the idea that you refer to the questions overide your own default weight, and store the answer? - It appears that a good chuck of the work will be done in the views and that a lot of checking will need to occur there? Is that OK? Again - feel free to give me better strategies!! Thanks

    Read the article

  • Suggestions for a django db structure

    - by rh0dium
    Hi Say I have the unknown number of questions. For example: Is the sky blue [y/n] What date were your born on [date] What is pi [3.14] What is a large integ [100] Now each of these questions poses a different but very type specific answer (boolean, date, float, int). Natively django can happily deal with these in a model. class SkyModel(models.Model): question = models.CharField("Is the sky blue") answer = models.BooleanField(default=False) class BirthModel(models.Model): question = models.CharField("What date were your born on") answer = models.DateTimeField(default=today) class PiModel(models.Model) question = models.CharField("What is pi") answer = models.FloatField() But this has the obvious problem in that each question has a specific model - so if we need to add a question later I have to change the database. Yuck. So now I want to get fancy - How do a set up a model where by the answer type conversion happens automagically? ANSWER_TYPES = ( ('boolean', 'boolean'), ('date', 'date'), ('float', 'float'), ('int', 'int'), ('char', 'char'), ) class Questions(models.model): question = models.CharField(() answer = models.CharField() answer_type = models.CharField(choices = ANSWER_TYPES) default = models.CharField() So in theory this would do the following: When I build up my views I look at the type of answer and ensure that I only put in that value. But when I want to pull that answer back out it will return the data in the format specified by the answer_type. Example 3.14 comes back out as a float not as a str. How can I perform this sort of automagic transformation? Or can someone suggest a better way to do this? Thanks much!!

    Read the article

  • Getting the last member of a group on an intermediary M2M

    - by rh0dium
    If we look at the existing docs, what is the best way to get the last member added? This is similar to this but what I want to do is to be able to do this. group = Group.objects.get(id=1) group.get_last_member_added() #This is by ('-date_added') <Person: FOO> I think the best way is through a manager but how do you do this on an intermediary model? class Person(models.Model): name = models.CharField(max_length=128) def __unicode__(self): return self.name class Group(models.Model): name = models.CharField(max_length=128) members = models.ManyToManyField(Person, through='Membership') def __unicode__(self): return self.name class Membership(models.Model): person = models.ForeignKey(Person) group = models.ForeignKey(Group) date_joined = models.DateField() invite_reason = models.CharField(max_length=64)

    Read the article

1