Search Results

Search found 4109 results on 165 pages for 'django paypal'.

Page 37/165 | < Previous Page | 33 34 35 36 37 38 39 40 41 42 43 44  | Next Page >

  • Django debug error

    - by Hulk
    I have the following in my model: class info(models.Model): add = models.CharField(max_length=255) name = models.CharField(max_length=255) An in the views when i say info_l = info.objects.filter(id=1) logging.debug(info_l.name) i get an error saying name doesnt exist at debug statement. 'QuerySet' object has no attribute 'name' 1.How can this be resolved. 2.Also how to query for only one field instead of selecting all like select name from info.

    Read the article

  • Django formsets: make first required?

    - by Mark
    These formsets are exhibiting exactly the opposite behavior that I want. My view is set up like this: def post(request): # TODO: handle vehicle formset VehicleFormSetFactory = formset_factory(VehicleForm, extra=1) if request.POST: vehicles_formset = VehicleFormSetFactory(request.POST) else: vehicles_formset = VehicleFormSetFactory() And my template looks like this: <div id="vehicle_forms"> {{ vehicles_formset.management_form }} {% for form in vehicles_formset.forms %} <h4>Vehicle {{forloop.counter}}</h4> <table> {% include "form.html" %} </table> {% endfor %} </div> That way it initially generates only 1 form, like I want. But I want that one form to be required! When I dynamically add blank forms with JavaScript and vehicles_formset.empty_form all those extra forms are required, which I don't want. From the docs: The formset is smart enough to ignore extra forms that were not changed. This is the behavior the first form is exhibiting (not what I want) but not the behavior that the extra forms are exhibiting (what I do want). Is there some attribute I can can change to at least make one form required?

    Read the article

  • Getting weird python error when I run a simple django script in Eclipse, not happening in console

    - by Rhubarb
    I am running a basic script that sets up the django environment by itself, to enable me to test the ORM features of django without having to implement web pages. The script then imports one of the types defined in my models. This error doesn't happen when I run this script from iPython, only from eclipse. Simply doing this import causes a weird exception like the following: Exception AttributeError: "'NoneType' object has no attribute 'print_exc'" in <bound method Signal._remove_receiver of <django.dispatch.dispatcher.Signal object at 0x026802B0>> ignored My script is as follows: from django.core.management import setup_environ import settings setup_environ(settings) from stats.models import Person for p in Person.objects.all(): print p.Name

    Read the article

  • Django authentication

    - by webvulture
    In my base.html file, I am using {% if user.is_authenticated %} <a href="#">{{user.username}}</a> {% else %} <a href="/acc/login/">log in</a> Here, even if the user is logged in, the log in button shows up. Now when I click on the log in link, it shows the username and also the normal login view, saying user is logged in. So, what's wrong?

    Read the article

  • Django, ModelForms, User and UserProfile - not hashing password

    - by IvanBernat
    I'm trying to setup a User - UserProfile relationship, display the form and save the data. When submitted, the data is saved, except the password field doesn't get hashed. Additionally, how can I remove the help_text from the username and password (inherited from the User model)? Full code is below, excuse me if it's too long. Models.py USER_IS_CHOICES = ( ('u', 'Choice A'), ('p', 'Choice B'), ('n', 'Ninja'), ) class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) user_is = models.CharField(max_length=1, choices=USER_IS_CHOICES) Forms.py class UserForm(forms.ModelForm): class Meta: model = User fields = ["first_name", "last_name", "username", "email", "password"] def clean_username(self): username = self.cleaned_data['username'] if not re.search(r'^\w+$', username): raise forms.ValidationError('Username can contain only alphanumeric characters') try: User.objects.get(username=username) except ObjectDoesNotExist: return username raise forms.ValidationError('Username is already taken') class UserProfileForm(forms.ModelForm): class Meta: model = UserProfile fields = ['user_is'] Views.py if request.method == 'POST': uform = UserForm(request.POST) pform = UserProfileForm(request.POST) if uform.is_valid() and pform.is_valid(): user = uform.save() profile = pform.save(commit = False) profile.user = user profile.save() return HttpResponseRedirect('/') else: uform = UserForm() pform = UserProfileForm() variables = RequestContext(request, { 'uform':uform, 'pform':pform }) return render_to_response('registration/register.html', variables)

    Read the article

  • How to elegantly create a datatable with Django ?

    - by Inshim
    Here's a common situation that I have and wish to avoid creating tedious loops and fiddling with html tables: I have a model Movie, which is has fkeys to Director and to Genre. How can I elegantly render a simple data table that has on one axis the different Directors, on another axis the different Genres, and inside each cell the count of the movies filtered by the respective Director and Genre? Thanks!

    Read the article

  • Django Haystack exact filtering

    - by blackrobot
    I have a haystack search which has the following SearchIndex: class GrantIndex(indexes.SearchIndex): """ This provides the search index for the Grant application. """ text = indexes.CharField(document=True, use_template=True) year = indexes.IntegerField(model_attr='year__year') date = indexes.DateField(model_attr='date') program = indexes.CharField(model_attr='program__area') grantee = indexes.CharField(model_attr='grantee') amount = indexes.IntegerField(model_attr='amount') site.register(Grant, GrantIndex) If I want to search filtering out any programs that ARE NOT 'Health', I run the following query: from haystack.query import SearchQuerySet sqs = SearchQuerySet() sqs = sqs.filter(program='Health') Unfortunately, this also produces objects from the program 'Health\Other' and 'Health\Cardiovascular'. How do I stop the search from allowing those other programs in? I run Ubuntu 9.10 with Xapian as my search back-end.

    Read the article

  • Add data to Django form class using modelformset_factory

    - by dean
    I have a problem where I need to display a lot of forms for detail data for a hierarchical data set. I want to display some relational fields as labels for the forms and I'm struggling with a way to do this in a more robust way. Here is the code... class Category(models.Model): name = models.CharField(max_length=160) class Item(models.Model): category = models.ForeignKey('Category') name = models.CharField(max_length=160) weight = models.IntegerField(default=0) class Meta: ordering = ('category','weight','name') class BudgetValue(models.Model): value = models.IntegerField() plan = models.ForeignKey('Plan') item = models.ForeignKey('Item') I use the modelformset_factory to create a formset of budgetvalue forms for a particular plan. What I'd like is item name and category name for each BudgetValue. When I iterate through the forms each one will be labeled properly. class BudgetValueForm(forms.ModelForm): item = forms.ModelChoiceField(queryset=Item.objects.all(),widget=forms.HiddenInput()) plan = forms.ModelChoiceField(queryset=Plan.objects.all(),widget=forms.HiddenInput()) category = "" < assign dynamically on form creation > item = "" < assign dynamically on form creation > class Meta: model = BudgetValue fields = ('item','plan','value') What I started out with is just creating a dictionary of budgetvalue.item.category.name, budgetvalue.item.name, and the form for each budget value. This gets passed to the template and I render it as I intended. I'm assuming that the ordering of the forms in the formset and the querset used to genererate the formset keep the budgetvalues in the same order and the dictionary is created correctly. That is the budgetvalue.item.name is associated with the correct form. This scares me and I'm thinking there has to be a better way. Any help would be greatly appreciated.

    Read the article

  • Django database caching

    - by hekevintran
    The object user has a foreign key relationship to address. Is there a difference between samples 1 and 2? Does sample 1 run the query multiple times? Or is the address object cached? # Sample 1 country = user.address.country city = user.address.city state = user.address.state # Sample 2 address = user.address country = address.country city = address.city state = address.state

    Read the article

  • django: displaying group users count in admin

    - by gruszczy
    I would like to change admin for a group, so it would display how many users are there in a certain group. I'd like to display this in the view showing all groups, the one before you enter admin for certain group. Is it possible? I am talking both about how to change admin for a group and how to add function to list_display.

    Read the article

  • How to deal with multiple sub-type of one super-type in Django admin

    - by Henri
    What would be the best solution for adding/editing multiple sub-types. E.g a super-type class Contact with sub-type class Client and sub-type class Supplier. The way shown here works, but when you edit a Contact you get both inlines i.e. sub-type Client AND sub-type Supplier. So even if you only want to add a Client you also get the fields for Supplier of vice versa. If you add a third sub-type , you get three sub-type field groups, while you actually only want one sub-type group, in the mentioned example: Client. E.g.: class Contact(models.Model): contact_name = models.CharField(max_length=128) class Client(models.Model): contact = models.OneToOneField(Contact, primary_key=True) user_name = models.CharField(max_length=128) class Supplier(models.Model): contact.OneToOneField(Contact, primary_key=True) company_name = models.CharField(max_length=128) and in admin.py class ClientInline(admin.StackedInline): model = Client class SupplierInline(admin.StackedInline): model = Supplier class ContactAdmin(admin.ModelAdmin): inlines = (ClientInline, SupplierInline,) class ClientAdmin(admin.ModelAdmin): ... class SupplierAdmin(admin.ModelAdmin): ... Now when I want to add a Client, i.e. only a Client I edit Contact and I get the inlines for both Client and Supplier. And of course the same for Supplier. Is there a way to avoid this? When I want to add/edit a Client that I only see the Inline for Client and when I want to add/edit a Supplier that I only see the Inline for Supplier, when adding/editing a Contact? Or perhaps there is a different approach. Any help or suggestion will be greatly appreciated.

    Read the article

  • Display additional data while iterating over a Django formset

    - by Jannis
    Hi, I have a list of soccer matches for which I'd like to display forms. The list comes from a remote source. matches = ["A vs. B", "C vs. D", "E vs, F"] matchFormset = formset_factory(MatchForm,extra=len(matches)) formset = MatchFormset() On the template side, I would like to display the formset with the according title (i.e. "A vs. B"). {% for form in formset.forms %} <fieldset> <legend>{{TITLE}}</legend> {{form.team1}} : {{form.team2}} </fieldset> {% endfor %} Now how do I get TITLE to contain the right title for the current form? Or asked in a different way: how do I iterate over matches with the same index as the iteration over formset.forms? Thanks for your input!

    Read the article

  • Django CSRF failure when form posts to a different frame

    - by Leopd
    I'm building a page where I want to have a form that posts to an iframe on the same page. The Template looks like this: <form action="form-results" method="post" target="resultspane" > {% csrf_token %} <input name="query"> <input type=submit> </form> <iframe src="form-results" name="resultspane" width="100%" height="70%"> </iframe> The view behind form-results is getting CSRF errors. Is there something special needed for cross-frame posting?

    Read the article

  • Django: Only one of two fields can be filled in

    - by Giovanni Di Milia
    I have this model: class Journals(models.Model): jid = models.AutoField(primary_key=True) code = models.CharField("Code", max_length=50) name = models.CharField("Name", max_length=2000) publisher = models.CharField("Publisher", max_length=2000) price_euro = models.CharField("Euro", max_length=2000) price_dollars = models.CharField("Dollars", max_length=2000) Is there a way to let people fill out either price_euro or price_dollars? I do know that the best way to solve the problem is to have only one field and another table that specify the currency, but I have constraints and I cannot modify the DB. Thanks!

    Read the article

  • Django model field value preprocessing before returning

    - by Satoru.Logic
    Hi, all. I have a Note model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content = NoteContentField(max_length=256) NoteContentField is a custom sub-class of CharField that override the to_python method in purpose of doing some twitter-text-conversion processing. class NoteContentField(models.CharField): __metaclass__ = models.SubfieldBase def to_python(self, value): value = super(NoteContentField, self).to_python(value) from ..utils import linkify return mark_safe(linkify(value)) However, this doesn't work. When I save a Note object like this: note = Note(author=request.use, content=form.cleaned_data['content']) The conversed value is saved into the database, which is not what I wanna see. Would you please tell me what's wrong with this? Thanks in advance.

    Read the article

  • Django - Better evaluation of relationship at the model level

    - by Brant
    Here's a simple relational pair of models. class Shelf(models.Model): name = models.CharField(max_length=100) def has_books(self): if Book.objects.filter(shelf=self): return True else: return False class Book(models.Model): shelf = models.ForeignKey(Shelf) name = models.CharField(max_length=100) Is there a better (or alternative) way to write the "has_book" method? I'm not a fan of the double database hit but I want to do this at the model level.

    Read the article

  • inverse relation to multiple inheriting classes in django

    - by Ofri Raviv
    Here are my schematic models: class Law(models.Model): ... class Bill(models.Model): ... # data for a proposed law, or change of an existing law class PrivateBill(Bill): ... # data for a Bill that was initiated by a parliament member class GovernmentBill(Bill): ... # data for a Bill that was initiated by the government It is possible and likely that in the future I (or maybe someone else) would want to add more Bill types. Every Bill should point to a Law (indicating what law this bill is going to change) and my question is: What is the best way to implement this? If I add the ForeignKey(Law) to Bill, I'll have a relation from every Bill to Law, but a Law would only have an inverse relation to Bills (bill_set), and not a different inverse relation to each type of bill. Of course I'll be able to filter each type of bill to get only the ones pointing to a specific Law, but this is something I think I'll need to use often, so I think having privatebill_set, governmentbill_set etc would make the code more readable. Another possible solution is to add the foreign key to each of the inheriting classes (this would give me a privatebill_set, governmentbill_set, futurebill_set), but that seems hairy because I would be relying on future programmers to remember to add that relation. How would you solve this?

    Read the article

  • Keeping track of changes - Django

    - by RadiantHex
    Hi folks!! I have various models of which I would like to keep track and collect statistical data. The problem is how to store the changes throughout time. I thought of various alternative: Storing a log in a TextField, open it and update it every time the model is saved. Alternatively pickle a list and store it in a TextField. Save logs on hard drive. What are your suggestions?

    Read the article

  • Django excluding specific instances from queryset without using field lookup

    - by Agos
    Hi, I sometimes have the need to make sure some instances are excluded from a queryset. This is the way I do it usually: unwanted_instance = Mymodel.objects.get(pk=bad_luck_number) uninteresting_stuff_happens() my_results = MyModel.objects.exclude(id=unwanted_instance.id) or, if I have more of them: my_results = MyModel.objects.exclude(id_in=[uw_in1.id, uw_in2.id, uw_in3.id]) This 'feels' a bit clunky, so I tried if I was lucky: my_ideally_obtained_results = MyModel.objects.exclude(unwanted_instance) Which doesn't work. But I read here on SO that a subquery can be used as parameter for exclude. Am I out of luck? Am I missing some functionality (checked the docs, but didn't find any useful pointer)

    Read the article

  • Complex Django filter question

    - by HWM-Rocker
    Lets say I have this class (simplified): class Tag (...): children = models.ManyToManyField(null=True, symmetrical=False) Now I already implemented the functions get_parents, get_all_ancestors. Is there a nice pythonic way to just the top level tags? If I had designed my Tags differently (to point to the parents instead) I would just make get_all_parents().filter(children=null). My first thought is to create a new function that will go recursively through all parents and save those that has none. But is there a possibility with filters or Query-objects to do the same (with fewer lines of code)? Thanks for your help. [edit] When it is finished, it should be a hierarchical tagging system. Each tag can have children, parents, but only the children are saved. I want to get all the top level tags, that point through many children / childrens children to my tag.

    Read the article

  • Changing User ModelAdmin for Django admin

    - by Leon
    How do you override the admin model for Users? I thought this would work but it doesn't? class UserAdmin(admin.ModelAdmin): list_display = ('email', 'first_name', 'last_name') list_filter = ('is_staff', 'is_superuser') admin.site.register(User, UserAdmin) I'm not looking to override the template, just change the displayed fields & ordering. Solutions please?

    Read the article

  • Doubt about django model API

    - by Clash
    Hello guys! So, here is what I want to do. I have a model Staff, that has a foreign key to the User model. I also have a model Match that has a foreign key to the User model. I want to select how much Matches every Staff has. I don't know how to do that, so far I only got it working for the User model. From Staff, it will not allow to annonate Match. This is what is working right now User.objects.annotate(ammount=Count("match")).filter(Q(ammount__gt=0)).order_by("ammount") And this is what I wanted to do Staff.objects.annotate(ammount=Count("match")).filter(Q(ammount__gt=0)).order_by("ammount") And by the way, is there any way to filter the matches? I want to filter the matches by a certain column. Thanks a lot in advance!

    Read the article

  • Check if Django model field choices exists

    - by Justin Lucas
    I'm attempting to check if a value exists in the choices tuple set for a model field. For example lets say I have a Model like this: class Vote(models.Model): VOTE_TYPE = ( (1, "Up"), (-1, "Down"), ) value = models.SmallIntegerField(max_length=1, choices=VOTE_TYPES) Now lets say in a view I have a variable new_value = 'Up' that I would like to use as the value field in a new Vote. How can I first check to see if the value of that variable exists in the VOTE_TYPE tuple? Thank you.

    Read the article

< Previous Page | 33 34 35 36 37 38 39 40 41 42 43 44  | Next Page >