Search Results

Search found 9244 results on 370 pages for 'django crispy forms'.

Page 34/370 | < Previous Page | 30 31 32 33 34 35 36 37 38 39 40 41  | Next Page >

  • Assigning a group while adding user in django-admin

    - by Lokharkey
    In my application, I have models that have the Users model as a Foreign key, eg: class Doctor(models.Model): username=models.ForeignKey(User, unique=True) ... In the admin site, when adding a new Doctor, I have the option of adding a new User next to the username field. This is exactly what I want, but in the dialog that opens, it asks for a username and password for the new user; I would also like to be able to assign a group to this new user. What would be the best way of doing this ? Thanks, lokharkey

    Read the article

  • django deleting models and overriding delete method

    - by Mike
    I have 2 models class Vhost(models.Model): dns = models.ForeignKey(DNS) user = models.ForeignKey(User) extra = models.TextField() class ApplicationInstalled(models.Model): user = models.ForeignKey(User) added = models.DateTimeField(auto_now_add=True) app = models.ForeignKey(Application) ver = models.ForeignKey(ApplicationVersion) vhost = models.ForeignKey(Vhost) path = models.CharField(max_length=100, default="/") def delete(self): # # remove the files # print "need to remove some files" super(ApplicationInstalled, self).delete() If I do the following >>> vhost = Vhost.objects.get(id=10) >>> vhost.id 10L >>> ApplicationInstalled.objects.filter(vhost=vhost) [<ApplicationInstalled: http://wiki.jy.com/>] >>> vhost.delete() >>> ApplicationInstalled.objects.filter(vhost=vhost) [] As you can see there is an applicationinstalled object linked to vhost but when I delete the vhost, the applicationinstalled object is gone but the print never gets called. Any easy way to do this without iterating through the objects in the vhost delete?

    Read the article

  • Django disable editing (but allow adding) in TabularInline view

    - by VoteyDisciple
    I want to disable editing ALL objects within a particular TabularInline instance, while still allowing additions and while still allowing editing of the parent model. I have this trivial setup: class SuperviseeAdmin(admin.TabularInline): model = Supervisee class SupervisorAdmin(admin.ModelAdmin): inlines = [SuperviseeAdmin] admin.site.register(Supervisor, SupervisorAdmin) I have tried adding a has_change_permission function to SuperviseeAdmin that returns False unconditionally, but it had no effect. I have tried setting actions = None in SuperviseeAdmin but it had no effect. What might I be overlooking that could get this to work?

    Read the article

  • Django Admin: OneToOne Relation as an Inline?

    - by Jim Robert
    I am putting together the admin for a satchmo application. Satchmo uses OneToOne relations to extend the base Product model, and I'd like to edit it all on one page. It is possible to have a OneToOne relation as an Inline? If not, what is the best way to add a few fields to a given page of my admin that will eventually be saved into the OneToOne relation? for example: class Product(models.Model): name = models.CharField(max_length=100) ... class MyProduct(models.Model): product = models.OneToOne(Product) ... I tried this for my admin but it does not work, and seems to expect a Foreign Key: class ProductInline(admin.StackedInline): model = Product fields = ('name',) class MyProductAdmin(admin.ModelAdmin): inlines = (AlbumProductInline,) admin.site.register(MyProduct, MyProductAdmin) Which throws this error: <class 'satchmo.product.models.Product'> has no ForeignKey to <class 'my_app.models.MyProduct'> Is the only way to do this a Custom Form? edit: Just tried the following code to add the fields directly... also does not work: class AlbumAdmin(admin.ModelAdmin): fields = ('product__name',)

    Read the article

  • Django User M2M relationship

    - by Antonio
    When trying to syncdb with the following models: class Contact(models.Model): user_from = models.ForeignKey(User,related_name='from_user') user_to = models.ForeignKey(User, related_name='to_user') class Meta: unique_together = (('user_from', 'user_to'),) User.add_to_class('following', models.ManyToManyField('self', through=Contact, related_name='followers', symmetrical=False)) I get the following error: Error: One or more models did not validate: auth.user: Accessor for m2m field 'following' clashes with related m2m field 'User.followers'. Add a related_name argument to the definition for 'following'. auth.user: Reverse query name for m2m field 'following' clashes with related m2m field 'User.followers'. Add a related_name argument to the definition for 'following'. auth.user: The model User has two manually-defined m2m relations through the model Contact, which is not permitted. Please consider using an extra field on your intermediary model instead. auth.user: Accessor for m2m field 'following' clashes with related m2m field 'User.followers'. Add a related_name argument to the definition for 'following'. auth.user: Reverse query name for m2m field 'following' clashes with related m2m field 'User.followers'. Add a related_name argument to the definition for 'following'.

    Read the article

  • Django select distinct sum

    - by yoshi
    I have the following (greatly simplified) table structure: Order: order_number = CharField order_invoice_number = CharField order_invoice_value = CharField An invoice number can be identical on more than one order (order O1 has invoice number I1, order O2 has invoice number I1, etc.). All the orders with the same invoice number have the same invoice value. For example: Order no. Invoice no. Value O1 I1 200 O2 I1 200 O3 I1 200 04 I2 50 05 I2 100 What I am trying to do is do a sum over all the invoice values, but don't add the invoices with the same number more than once. The sum for the above items would be: 200+50+100. I tried doing this using s = orders.values('order_invoice_id').annotate(total=Sum('order_invoice_value')).order_by() and s = orders.values('order_invoice_id').order_by().annotate(total=Sum('order_invoice_value')) but I didn't get the desired result. I tried a few different solutions from similar questions around here but I couldn't get the desired result. I can't figure out what I'm doing wrong and what I actually should do to get a sum that uses each invoice value just once.

    Read the article

  • Break nested loop in Django views.py with a function

    - by knuckfubuck
    I have a nested loop that I would like to break out of. After searching this site it seems the best practice is to put the nested loop into a function and use return to break out of it. Is it acceptable to have functions inside the views.py file that are not a view? What is the best practice for the location of this function? Here's the example code from inside my views.py @login_required def save_bookmark(request): if request.method == 'POST': form = BookmarkSaveForm(request.POST) if form.is_valid(): bookmark_list = Bookmark.objects.all() for bookmark in bookmark_list: for link in bookmark.link_set.all(): if link.url == form.cleaned_data['url']: # Do something. break else: # Do something else. else: form = BookmarkSaveForm() return render_to_response('save_bookmark_form.html', {'form': form})

    Read the article

  • problem in decoupling urls.py , while following a tutorial of django

    - by Nitin Garg
    http://docs.djangoproject.com/en/dev/intro/tutorial03/ I was at the step Decoupling the URLconfs where the tutorial illustrates how to decouple urls.py. On doing exactly what it says, i get the following error- error at /polls/1/ nothing to repeat Request Method: GET Request URL: http://localhost:8000/polls/1/ Exception Type: error Exception Value: nothing to repeat Exception Location: C:\jython2.5.1\Lib\re.py in _compile, line 241 Python Executable: C:\jython2.5.1\jython.bat Python Version: 2.5.1 Python Path: ['E:\\Programming\\Project\\django_app\\mysite', 'C:\\jython2.5.1\\Lib\\site-packages\\setuptools-0.6c11-py2.5.egg', 'C:\\jython2.5.1\\Lib', '__classpath__', '__pyclasspath__/', 'C:\\jython2.5.1\\Lib\\site-packages'] Server time: Mon, 12 Apr 2010 12:02:56 +0530

    Read the article

  • Django-pyodbc mssql/freetds server connection problems on linux

    - by wizard
    Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnectW)') I'm migrating from developing on a windows development machine to linux machine in production and I'm having issues with the freetds driver. As far as I can tell that error message means it can't find the driver. I can connect via the cli via sqsh and tsql. I've setup my settings.py as such. 'bc2db': { 'ENGINE': 'sql_server.pyodbc', 'NAME': 'DataTEST', 'USER': 'appuser', 'PASSWORD': 'PASS', 'HOST': 'bc2.domain.com', 'options': { 'driver': 'FreeTDS', } }, Does anyone have any mssql experience with djano? do I have to use a dns? (how would I format that?) Thanks

    Read the article

  • Django Class Views and Reverse Urls

    - by kalhartt
    I have a good many class based views that use reverse(name, args) to find urls and pass this to templates. However, the problem is class based views must be instantiated before urlpatterns can be defined. This means the class is instantiated while urlpatterns is empty leading to reverse throwing errors. I've been working around this by passing lambda: reverse(name, args) to my templates but surely there is a better solution. As a simple example the following fails with exception: ImproperlyConfigured at xxxx The included urlconf mysite.urls doesn't have any patterns in it mysite.urls from mysite.views import MyClassView urlpatterns = patterns('', url(r'^$' MyClassView.as_view(), name='home') ) views.py class MyClassView(View): def get(self, request): home_url = reverse('home') return render_to_response('home.html', {'home_url':home_url}, context_instance=RequestContext(request)) home.html <p><a href={{ home_url }}>Home</a></p> I'm currently working around the problem by forcing reverse to run on template rendering by changing views.py to class MyClassView(View): def get(self, request): home_url = lambda: reverse('home') return render_to_response('home.html', {'home_url':home_url}, context_instance=RequestContext(request)) and it works, but this is really ugly and surely there is a better way. So is there a way to use reverse in class based views but avoid the cyclic dependency of urlpatterns requiring view requiring reverse requiring urlpatterns...

    Read the article

  • Django: Breaking up views

    - by Brant
    This is really just a "best practices" question... I find that When developing an app, I often end up with a lot of views. Is it common practice to break these views up into several view files? In other words... instead of just having views.py, is it common to have views_1.py, views_2.py, views_3.py (but named more appropriately, perhaps by category)?

    Read the article

  • Delete manytomanyfield in Django

    - by Mike
    I have the following models class Database(models.Model): user = models.ForeignKey(User) name = models.CharField(max_length=100) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) class DatabaseUser(models.Model): user = models.ForeignKey(User) name = models.CharField(max_length=100) password = models.CharField(max_length=100) database = models.ManyToManyField(Database) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) One DatabaseUser can have many Databases under it's control. The issue I have if I go to delete a Database it wants to Delete the DatabaseUser also.. Is there a way to stop this from happening easily?

    Read the article

  • django: Display image in admin interface

    - by Oleg Tarasenko
    Hi, I've defined a model which contains a link an image. Is there a way to display the image in the model items list. (e.g. if I defined an article this way: class Article(models.Model): url = models.CharField(max_length = 200, unique = True, help_text="/lessons/") title = models.CharField(max_length = 500) img = models.CharField(max_length = 100) # Contains path to image def __unicode__(self): return u"%s" %title ) Is there a way to display image together with title?

    Read the article

  • Extending User object in Django: User model inheritance or use UserProfile?

    - by Chris
    To extend the User object with custom fields, the Django docs recommend using UserProfiles. However, according to this answer to a question about this from a year or so back: extending django.contrib.auth.models.User also works better now -- ever since the refactoring of Django's inheritance code in the models API. And articles such as this lay out how to extend the User model with custom fields, together with the advantages (retrieving properties directly from the user object, rather than through the .get_profile()). So I was wondering whether there is any consensus on this issue, or reasons to use one or the other. Or even what the Django team currently think?

    Read the article

  • 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

  • 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

  • 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

  • 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

< Previous Page | 30 31 32 33 34 35 36 37 38 39 40 41  | Next Page >