Search Results

Search found 7702 results on 309 pages for 'django validation'.

Page 139/309 | < Previous Page | 135 136 137 138 139 140 141 142 143 144 145 146  | Next Page >

  • [Django] How do I filter the choices in a ModelForm that has a CharField with the choices attribute

    - by nubela
    I understand I am able to filter queryset of Foreignkey or Many2ManyFields, however, how do I do that for a simple CharField that is a Select Widget (Select Tag). For example: PRODUCT_STATUS = ( ("unapproved", "Unapproved"), ("approved", "Listed"), #("Backorder","Backorder"), #("oos","Out of Stock"), #("preorder","Preorder"), ("userdisabled", "User Disabled"), ("disapproved", "Disapproved by admin"), ) and the Field: o_status = models.CharField(max_length=100, choices=PRODUCT_STATUS, verbose_name="Product Status", default="approved") Suppose I wish to limit it to just "approved" and "userdisabled" instead showing the full array (which is what I want to show in the admin), how do I do it? Thanks!

    Read the article

  • Best practice: How to persist simple data without a database in django?

    - by Infinity
    I'm building a website that doesn't require a database because a REST API "is the database". (Except you don't want to be putting site-specific things in there, since the API is used by mostly mobile clients) However there's a few things that normally would be put in a database, for example the "jobs" page. You have master list view, and the detail views for each job, and it should be easy to add new job entries. (not necessarily via a CMS, but that would be awesome) e.g. example.com/careers/ and example.com/careers/77/ I could just hardcode this stuff in templates, but that's no DRY- you have to update the master template and the detail template every time. What do you guys think? Maybe a YAML file? Or any better ideas? Thx

    Read the article

  • what is the 'extra' mean in this django code..

    - by zjm1126
    TOPIC_COUNT_SQL = """ SELECT COUNT(*) FROM topics_topic WHERE topics_topic.object_id = maps_map.id AND topics_topic.content_type_id = %s """ MEMBER_COUNT_SQL = """ SELECT COUNT(*) FROM maps_map_members WHERE maps_map_members.map_id = maps_map.id """ maps = maps.extra(select=SortedDict([ ('member_count', MEMBER_COUNT_SQL), ('topic_count', TOPIC_COUNT_SQL), ]), select_params=(content_type.id,)) i don't know this mean, thanks

    Read the article

  • Django database - how to add this column in raw SQL.

    - by alex
    Suppose I have my models set up already. class books(models.Model): title = models.CharField... ISBN = models.Integer... What if I want to add this column to my table? user = models.ForeignKey(User, unique=True) How would I write the raw SQL in my database so that this column works?

    Read the article

  • Django - Problem with models/manager to organise a query...

    - by user296644
    Hi, I have an application to count the number of access to an object for each website in a same database. class SimpleHit(models.Model): """ Hit is the hit counter of a given object """ content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') site = models.ForeignKey(Site) hits_total = models.PositiveIntegerField(default=0, blank=True) [...] class SimpleHitManager(models.Manager): def get_query_set(self): print self.model._meta.fields qset = super(SimpleHitManager, self).get_query_set() qset = qset.filter(hits__site=settings.SITE_ID) return qset class SimpleHitBase(models.Model): hits = generic.GenericRelation(SimpleHit) objects = SimpleHitManager() _hits = None def _db_get_hits(self, only=None): if self._hits == None: try: self._hits = self.hits.get(site=settings.SITE_ID) except SimpleHit.DoesNotExist: self._hits = SimpleHit() return self._hits @property def hits_total(self): return self._db_get_hits().hits_total [...] class Meta: abstract = True And I have a model like: class Model(SimpleHitBase): name = models.CharField(max_length=255) url = models.CharField(max_length=255) rss = models.CharField(max_length=255) creation = AutoNowAddDateTimeField() update = AutoNowDateTimeField() So, my problem is this one: when I call Model.objects.all(), I would like to have one request for the SQL (not two). In this case: one for Model in order to have information and one for the hits in order to have the counter (hits_total). This is because I cannot call directly hits.hits_total (due to SITE_ID?). I have tried select_related, but it seems to do not work... Question: - How can I add column automatically like (SELECT hits.hits_total, model.* FROM [...]) to the queryset? - Or use a functional select_related with my models? I want this model could be plugable on all other existing model. Thank you, Best regards.

    Read the article

  • Django date filter: how come the format used is different from the one in datetime library?

    - by sebpiq
    For formatting a date using date filter you must use the following format : {{ my_date|date:"Y-m-d" }} If you use strftime from the standard datetime, you have to use the following : my_date.strftime("%Y-%m-%d") So my question is ... isn't it ugly (I guess it is because of the % that is used also for tags, and therefore is escaped or something) ? But that's not the main question ... I would like to use the same DATE_FORMAT parametrized in settings.py all over the project, but it therefore seems that I cannot ! Is there a work around (for example a filter that removes the % after the date has been formatted like {{ my_date|date|dream_filter }}, because if I just use DATE_FORMAT = "%Y-%m-%d" I got something like %2001-%6-%12)?

    Read the article

  • How do I set up gaeunit 2.0a with my Django app?

    - by J. Frankenstein
    I am trying to set up Google App Engine unit testing for my web application. I downloaded the file from here. I followed the instructions in the readmen by copying the directory gaeunit into the directory with the rest of my apps and registering 'gaeunit' in settings.py. This didn't seem sufficient to actually get things going. I also stuck url('^test(.*)', include('gaeunit.urls')) into my urls.py file. When I go to the url http://localhost:8000/test, I get the following error: [Errno 2] No such file or directory: '../../gaeunit/test' Any suggestions? I'm not sure what I've done wrong. Thanks!

    Read the article

  • Django. Invalid keyword argument for this function. ManyToMany

    - by sagem_tetra
    I have this error: 'people' is an invalid keyword argument for this function class Passage(models.Model): name= models.CharField(max_length = 255) who = models.ForeignKey(UserProfil) class UserPassage(models.Model): passage = models.ForeignKey(Passage) people = models.ManyToManyField(UserProfil, null=True) class UserProfil(models.Model): user = models.OneToOneField(User) name = models.CharField(max_length=50) I try: def join(request): user = request.user user_profil = UserProfil.objects.get(user=user) passage = Passage.objects.get(id=2) #line with error up = UserPassage.objects.create(people= user_profil, passage=passage) return render_to_response('thanks.html') How to do correctly? Thanks!

    Read the article

  • Symfony 2 form repeated validation in Entity with annotation

    - by Sukhrob
    My question is "How can I do form repeated validation in Entity with annotation?". I have an Account entity with (email, password and confirmPassword) attributes. When a new user registers a new account, he/she has to fill in email, password and confirmPassword fields. Obviously, password and confirmPassword fields must match. I saw an example of this validation with pure php (form builder) in Stachoverflow like below. $builder->add('password', 'repeated', array( 'type' => 'password', 'first_name' => 'Password', 'second_name' => 'Password confirmation', 'invalid_message' => 'Passwords are not the same', )); But, this is not what I want. I want this functionality with annotation in my Account entity. Maybe * @Assert\Match( * matchField = "password", * message = "The password confirmation does not match password." * ) protected $confirmPassword;

    Read the article

  • how can i introspect properties and model fields in django?

    - by shreddd
    I am trying to get a list of all existing model fields and properties for a given object. Is there a clean way to instrospect an object so that I can get a dict of fields and properties. class MyModel(Model) url = models.TextField() def _get_location(self): return "%s/jobs/%d"%(url, self.id) location = property(_get_location) What I want is something that returns a dict that looks like this: { 'id' : 1, 'url':'http://foo', 'location' : 'http://foo/jobs/1' } I can use model._meta.fields to get the model fields, but this doesn't give me things that are properties but not real DB fields.

    Read the article

  • webapp and django framework

    - by Joel
    As far as I understand, the "Getting Started" guide of GAE with Python uses the webapp framework. However, it seems like it uses Django to render templates. Does that mean that I can use the Django template engine without using its application framework?

    Read the article

  • SelfValidation in DataAnnotations?

    - by DotnetDude
    With Validation Application block, there's the following functionality: Creating Custom attributes Creating SelfValidation on the type Ability to read from external config file I plan to use the DataAnnotations to replace the Validation application block. Are the above possible with DataAnnotations? If so, how'd I implement them?

    Read the article

< Previous Page | 135 136 137 138 139 140 141 142 143 144 145 146  | Next Page >