Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
django get() is returning a tuple instead of the object itself
I've got several models and I am passing an instance of each of them to my template through the context dictionary: def suite(request, oem_name_slug, project_name_slug, variant_name_slug, suite_name_slug): s = Suite.objects.get(slug=suite_name_slug), context_dict = dict( oem=OEM.objects.get(slug=oem_name_slug), project=Project.objects.get(slug=project_name_slug), variant=Variant.objects.get(slug=variant_name_slug), group=s[0].group, suite=s, ) return render(request, r'vtc\suite.html', context_dict) The issue I'm having is that the first get(): s = Suite.objects.get(slug=suite_name_slug) is returning a tuple with the object I'm trying to retrieve as the first element, instead of returning the object directly as I would expect from the documentation. Note that I'm not using get_or_create(), which would of course return a tuple. The other get() commands are working as I would expect. Suite.objects.get(slug=suite_name_slug) gives (<Suite: $SuiteName>,) Project.objects.get(slug=project_name_slug) gives <Project: $ProjectName> Here are the models for each: class Suite(models.Model): group = models.ForeignKey(Group, related_name='suites') name = models.CharField(max_length=NAME_MAX_LENGTH, default='') slug = models.SlugField(default='') def save(self, *args, **kwargs): self.slug = slugify(self.name) super(Suite, self).save(*args, **kwargs) class Meta: unique_together = ( ('group', 'name'), ) def __unicode__(self): return self.name class Project(models.Model): oem = models.ForeignKey(OEM, related_name='projects') name = models.CharField(max_length=NAME_MAX_LENGTH, default='') slug = models.SlugField(default='') def save(self, *args, **kwargs): self.slug = slugify(self.name) super(Project, self).save(*args, **kwargs) class Meta: unique_together = ( ('oem', 'name'), ) def __unicode__(self): return self.name -
Django ModelForm not storing foreignkey in modeladmin
I have the following code which is supposed to create a MyConfig object. However, it doesn't as the app_model is always returned as None. The idea is to choose from a select few contenttypes and then add a key, and the resulting config will trigger a bunch of services. However whenever I save the form, the contenttype stored in the app_model is always None, which is clearly undesirable Here is the admin: class ContentTypeModelChoiceField(ModelChoiceField): def label_from_instance(self, obj): return "{}-{}".format(obj.app_label, obj.model) class MyConfigForm(ModelForm): class Meta: model = models.MyConfig fields = '__all__' def __init__(self, *args, **kwargs): super(MyConfigForm, self).__init__(*args, **kwargs) self.fields['app_model'].label = "App Name" app_model = ContentTypeModelChoiceField( ContentType.objects.filter( app_label__startswith='myApp', model="myModel", ), empty_label="Choose a model", ) class MyConfigAdmin(admin.ModelAdmin): model = models.MyConfig form = MyConfigForm list_display = (<display fields> ) search_fields = (<search fields> ) And here is the model itself: class MyConfig(models.Model): app_model = models.ForeignKey(ContentType, null=True) ref_key = models.CharField(max_length=32, null=True) -
Using images in CSS with Jinja and Django
I am making my first blog with Django, everything is working fine, but I can seem to load my burger img with CSS in my blog_app. blog_app -templates --include_core ---blog.html --blog_app ---blog_app.html ---blog_post.html -static --include_core ---fonts ---js ---css ----mobile.css ----style.css ---images ----mobile -----mobile-menu.png so include_core is basicly the folder where the main template will be placed. It is working perfectly. I tried with this example and everything was working fine: <img src="{% static 'include_core/images/moon-satellite.jpg' %}" alt=""> blog_app/templates/include_core/blog.html <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title><!-- blog - Space Science Website Template --></title> {% load static %} <link rel="stylesheet" href="{% static 'include_core/css/style.css' %}" type="text/css"> <link rel="stylesheet" type="text/css" href="{% static 'include_core/css/mobile.css' %}"> <script src="{% static 'include_core/js/mobile.js' %}" type="text/javascript"></script> </head> blog_app/static/include_core/mobile.css #header div span#mobile-navigation { background: transparent url("images/mobile/mobile-menu.png") no-repeat; display: block; height: 50px; margin: 0; padding: 0 0 0 0; position: absolute; right: 3%; top: 14px; width: 50px; z-index: 999; } JavaScript file: window.onload = function(){ var getNavi = document.getElementById('navigation'); var mobile = document.createElement("span"); mobile.setAttribute("id","mobile-navigation"); getNavi.parentNode.insertBefore(mobile,getNavi); document.getElementById('mobile-navigation').onclick = function(){ var a = getNavi.getAttribute('style'); if(a){ getNavi.removeAttribute('style'); document.getElementById('mobile-navigation').style.backgroundImage='url(images/mobile/mobile-menu.png)'; } else { getNavi.style.display='block'; document.getElementById('mobile-navigation').style.backgroundImage='url(images/mobile/mobile-close.png)'; } }; Here is the problem: in the desktop version there shouldn't be no hamburger button(mobile-menu.png), there should be only in the … -
How to render Django CheckboxSelectMultiple in template?
I'm new to Django and having trouble understanding how to use CheckboxSelectMultiple to manually render a group of checkboxes in a template. I have a form to display checkboxes for different car models: class CarForm(forms.Form): MODELS = ( ('bmw', 'BMW'), ('mer', 'Mercedes'), ('tes', 'Tesla'), ('oth', 'Other'), ) car = forms.MultipleChoiceField( choices = MODELS, widget = forms.CheckboxSelectMultiple() ) The user can check more than one checkbox but they need to check at least one. Most examples render the instances in a for loop with as_p but I want the template to lay them out as shown below without being embedded inside HTML ul and li tags: Car Models: [ ] BMW [ ] Mercedes [ ] Tesla [ ] Other I put a set_trace in my view and stopped to examine the form before it's passed to the template for rendering and I can see I'm passing the template the form fields I want: >>> form.fields['car'].choices[1][0] >>> 'mer' >>> form.fields['car'].choices[1][1] >>> 'Mercedes' But I don't understand how to code the template to display what are in these checkbox fields so that I get this: Car Models: <label><input type="checkbox" value="bmw" />BMW</label> <label><input type="checkbox" value="mer" />Mercedes</label> <label><input type="checkbox" value="tes" />Tesla</label> <label><input type="checkbox" value="oth" … -
Django: how to completely skip a migration?
I want to be able to not run a Django 1.8 migration. I have seen people use the --fake option, but it's not a valid alternative for me, since it writes a new record on the django migrations database table. I dont like this, because I want to be able to run that migration on a later moment, and that wouldn't happen since django thinks it has been already done. Is there any other way of avoiding to run a migration? -
'Document matching query does not exist in django-celery
I am trying to run a async task using django-celery and I am not sure why it keeps coming with this error. So, my setup is as follows: I have installed redis as the messaging service and I can verify that it is running. My settings.py file has the following lines related to django-celery: import djcelery # Setup celery djcelery.setup_loader() BROKER_URL = 'redis://localhost:6379/0' CELERY_IMPORTS = ("myproject.tasks", ) I have the celery worker running as: python manage.py celery worker --loglevel=info -E -B This returns -------------- celery@gsp v3.1.23 (Cipater) ---- **** ----- --- * *** * -- Linux-4.4.0-38-generic-x86_64-with-debian-stretch-sid -- * - **** --- - ** ---------- [config] - ** ---------- .> app: default:0x7f8aab484da0 (djcelery.loaders.DjangoLoader) - ** ---------- .> transport: redis://localhost:6379/0 - ** ---------- .> results: - *** --- * --- .> concurrency: 12 (prefork) -- ******* ---- --- ***** ----- [queues] -------------- .> celery exchange=celery(direct) key=celery [tasks] . myproject.tasks.add . myproject.tasks.generate_cbf_maps . myproject.tasks.sleeptask One of the models is defined as: class LabelModel(models.Model): image = models.FileField(upload_to='documents/label', db_column='path', default='Some Value') This is referred to by another model as: class Document(models.Model): labelled_image = models.ForeignKey(LabelModel, db_column='label') Now, one of the celery tasks is defined as: @celery.task def generate_cbf_maps(document_id): obj = Document.objects.get(pk=document_id) and when I call this … -
DoesNotExist at /admin/login/ , django admin not working, django registration redux
iam new to django and i started a blog app. after a while when i want to login into the admin 0.0.0.1:8000/admin I get an error DoesNotExist at /admin/login/ Site matching query does not exist. I have no idea why. Maybe it has something to do, that I installed django-registration-redux or with my urlpatterns in main and in the blog app. Maybe somebody can give me advice also about better urlpatterns? My main aim is to do a create view with login required mixin. This doesnt work too when i put the loginrequiredmixin in the class blog_postCreateView. I appreciate every help. Iam new (noob). Looking forward for your answer. IF there is anything what i can improve just tell me , thanks Thanks a lot main url from django.conf.urls import url, include from django.contrib import admin from blog.views import AboutPageView, ContactPageView, blog_postCreateView urlpatterns = [ url(r'', include('blog.urls')), url(r'^blog/', include('blog.urls')), url(r'^about/$', AboutPageView.as_view(), name='about'), url(r'^contact/$', ContactPageView.as_view(), name='contact'), url(r'^create/$', blog_postCreateView.as_view(), name='blog_post_create'), #admin and login url(r'^admin/', admin.site.urls), url(r'^accounts/', include('registration.backends.default.urls')), ] blog urls from django.conf.urls import url from .views import blog_postListView, blog_postDetailView, blog_postCreateView urlpatterns = [ url(r'^$', blog_postListView.as_view(), name='blog_post_list'), url(r'^(?P<slug>[-\w]+)$', blog_postDetailView.as_view(), name='blog_post_detail'), ] views from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse from django.http import … -
Form not displaying all of my fields
Disclaimer: Total newbie here! So I am creating a registration process for the app I am building and for some reason even though I have defined first_name and last_name fields they are not showing up in my form. I am not sure what is going on with it but any help would be appreciated. Please see my code and screenshots below. forms.py from django import forms from django.contrib.auth.models import User from django.contrib.auth.forms import UserCreationForm class RegistrationForm(UserCreationForm): email = forms.EmailField(required=True) class Meta: model = User fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2') def save(self, commit=True): user = super(RegistrationForm, self).save(commit=False) user.first_name = self.cleaned_data['first_name'] user.last_name = self.cleaned_data['last_name'] user.email = self.cleaned_data['email'] if commit: user.save() return user views.py from django.shortcuts import render, render_to_response from django.http import HttpResponseRedirect from django.contrib.auth.forms import UserCreationForm from django.template.context_processors import csrf from django.contrib.auth.models import User from .forms import RegistrationForm def register(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/accounts/register/complete') else: form = RegistrationForm() token = {} token.update(csrf(request)) token['form'] = form return render('registration/registration_form.html', token) template {% extends "base.html" %} {% block title %}Register{% endblock %} {% block content %} <h2>Registration</h2> <form action="/accounts/register/" method="post">{% csrf_token %} {{form.as_p}} <input type="submit" value="Register" /> </form> {% endblock %} What I am … -
Execute JavaScript on Django Page through URL without reload
i have a webpage that loads certain JavaScript packages. www.mySite.com If i enter JavaScript commands in the browser console, i am able to interact with them. Lets take alert('5') as a simple example. I would like the same JavaScript calls to be executed without the browser console but through a specific URL like: www.mySite.com/?value=5 so that this leads to an execution of my JavaScript commands? Without the Page beeing reloaded/refreshed but staying in the actual state. My approach was to catch the extended URL in my Django View and execute the JavaScript command. View: class ShowPage(View): def get(self, request, caseId): value = request.GET.get('value', '') if(value is not ''): // execute JavaScript here... return HttpResponse("<script>alert(" + value + ")</script>") else: ... return render(request, 'template.html', context) But this leads to a loss of my page where i entered the URL. Does anyone has an idea how to preserve the actual Browser content? So that it is possible to call the loaded Javascript packages? -
Django login redirect to wrong page
im currently working on tango with django tutorial and in part with loging in i have a problem. After i click on log in the POST is not going to rango/login but to rango/login/rango/login. Can anyone help me fix this problem and more importantly explain this behavior to me ? user_login method in views.py def user_login(request): if request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') user = authenticate(username=username, password = password) if user: if user.is_active: login(request, user) return HttpResponseRedirect(reverse('index')) else: return HttpResponse("Your account is disabled") else: print ('invalid login details: {0}, {1}'.format(username,password)) return HttpResponse("Invalid login details supplied") else: return render(request, 'rango/login.html', {}) url url(r'^login/$', views.user_login, name = 'login'), form in html file <h1>login into rango</h1> <br /> <form id="login_form" method="post" action="/rango/login/"> {% csrf_token %} Username: <input type="text" name="username" value="" size="50"/> <br /> Password: <input type="password" name="password" value="" size="50"/> <br /> <input type="submit" value="submit"/> Thank you for your reactions ! -
Django ORM relatedquery
How do I make a query in Django similar to SELECT * FROM tag_document INNER JOIN document ON document.id = tag_document.doc_id My models are the following: class Tag(models.Model): name = models.CharField(max_length=256, unique=True) description = models.TextField(default='') class Document(models.Model): name = models.CharField(max_length=256, unique=True, default='') description = models.TextField(default='') url = models.URLField() tags = models.ManyToManyField(Tag) -
How to point blog to menu item in Mezzanine?
How do you point blogs to a menu item in Mezzanine? I am able to point my blogs to Home using urls.py but how about page types like link and richtext? -
How to display "x days ago" for the time 1 day before and show time "x hours ago" for today in django by filters [duplicate]
This question already has an answer here: User-friendly time format in Python? 10 answers I am Stuck in in this little thing.I want to show ago time for particular post. Django provide timesince filter which return always like 1 day and 3 hours ago or 5 days 3 hours ago. But i want that post posted on today it shows " x hours ago" and if post before today it show me " x days ago" only. How can i get it.This Question already posted in stackOverflow but that doesnot solved my problem. Any help will be appreciated. Thanks in advance. -
I contributed to cleanup the documentation. Rejected as invalid. I don't agree [duplicate]
This question is an exact duplicate of: Documentation: both data and initial for formset Django 1.10.1 My ticket: https://code.djangoproject.com/ticket/27280 Simulated situation: https://bitbucket.org/Kifsif/formsets/commits/f5e05aa61bcfe4be776bd1acc436589d27c78d29 The ticket is closed. The answer was: "Without initial data, the formset will output 1 empty form". Could you help me understand who is right. Earlier in the documentation there was: ArticleFormSet = formset_factory(ArticleForm, min_num=3, validate_min=True) In this case how can a formset with data for 3 forms produce one empty form? In the initial we have meat for 2 forms. And how can it fill the third one? In my opinion this is a surrealism somehow. I suppose that in vain he closed my ticket. But I'm too green. Maybe I'm wrong. And if I'm right, what to do? Create new ticket? -
Using PayPal mass payments with Django
I have figured out how to receive payments using django-paypal library from python, but i couldn't find the feature that would send the funds to other users. Although there wasn't such feature in django-paypal, i have found out PayPal's mass payments from API, but i couldn't understand how would i use it in Python. So for example, i know the email of user, how could i send 5$ by just email information. Code Example: import random User = "example@example.com" import MassivePay def Sender(): MassivePay.sendto = random.choice(User) MassivePay.send("5") if __name__ == "__main__": p = Process(target=Sender) p.start() I know it's too easy example demonstrated in code, but how could it be seriously done in Django? Is there any library specially designed for framework? Or Python itself? If so how can i use it? -
ImportError: No module named 'models' in Python 3
I have a new Python project, with a models.py file that looks like this: from django.db import models from django.contrib.auth.models import User from django.core.validators import MinValueValidator, MaxValueValidator class Metric(models.Model): users = models.ManyToManyField(User, through = 'Vote') name = models.CharField(max_length = 255) class Vote(models.Model): metric = models.ForeignKey(Metric, on_delete = models.CASCADE) user = models.ForeignKey(User, on_delete = models.CASCADE) rating = models.IntegerField(validators = [MinValueValidator(0), MaxValueValidator(10)]) email = models.EmailField def __str__(self): return str(self.rating) and an admin.py file like this: from django.contrib import admin from models import Metric, Vote admin.site.register(Metric) admin.site.register(Vote) When running this with Python 2.7.5, launching the app works fine. When I try to run it using Python 3.5.1, I get the error ImportError: No module named 'models', with this backtrace: Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x103bd2b70> Traceback (most recent call last): File "/Users/sashacooper/pyenv/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper fn(*args, **kwargs) File "/Users/sashacooper/pyenv/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 113, in inner_run autoreload.raise_last_exception() File "/Users/sashacooper/pyenv/lib/python3.5/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception six.reraise(*_exception) File "/Users/sashacooper/pyenv/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise raise value.with_traceback(tb) File "/Users/sashacooper/pyenv/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper fn(*args, **kwargs) File "/Users/sashacooper/pyenv/lib/python3.5/site-packages/django/__init__.py", line 27, in setup apps.populate(settings.INSTALLED_APPS) File "/Users/sashacooper/pyenv/lib/python3.5/site-packages/django/apps/registry.py", line 115, in populate app_config.ready() File "/Users/sashacooper/pyenv/lib/python3.5/site-packages/django/contrib/admin/apps.py", line 23, in ready self.module.autodiscover() File "/Users/sashacooper/pyenv/lib/python3.5/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover autodiscover_modules('admin', register_to=site) File "/Users/sashacooper/pyenv/lib/python3.5/site-packages/django/utils/module_loading.py", … -
django-pgcrypto: AttributeError: module 'django.db.models' has no attribute 'SubfieldBase'
I am trying to add django-pgcrypto to my django project but I am getting an error message: class EncryptedTextField (six.with_metaclass(models.SubfieldBase, BaseEncryptedField)): AttributeError: module 'django.db.models' has no attribute 'SubfieldBase' Do you have any advice on how this could be fixed? I am using django 1.10 and python 3.5 -
How to ignore folder in just post_process while collectstatic django?
Is there any way to ignore a folder only for post_process() when running collectstatic? Im running the following command: python manage.py collectstatic --noinput -i libs But the issue is that it ignores collecting the files from libs folder as well and I would like to collect the files but no execute post_process() for libs. using --no-post-process ignores completely post_process(), so in our use case is not applicable. -
How to get the AccessToken Id?
I am working with creation of Application and the AccessToken for Django oauth toolkit. I have created an AccessToken object and now trying to get the 'generated token', using the command, "curl -X post -d "client_id=&client_secret=&grant_type=password&username=&password=" path:8000/admin/oauth2_provider/accesstoken/" Instead of getting the valid response I am receiving, "Forbidden (403) CSRF verification failed. Request aborted." My Questions are: 1. Should the url be accessed with admin or without it? 2. How can I get the token id? 3. When I run the command, "curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer gen_token" -d '{a:b,}' url_path" this error occured, At what time does this error occurs and why?, '{"detail":"Authentication credentials were not provided."}'. PS: https://django-oauth-toolkit.readthedocs.io/en/latest/rest-framework/getting_started.html -
django custom permission to some views
I have some class-based view. And i have a User model with field somepermission = models.BooleanField(default=False) How can i restrict permission to view? Is this possible with PermissionRequiredMixin? views.py from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin class LoggedInPermissionMixin(PermissionRequiredMixin): if self.request.user.somepermission: redirect ... Can i do this way? Also how can i only show pop-up(You have no "somepermission" to view this) when go to that view? -
Hidden/display none attribute keeps getting added
In my django project I am trying to display some image to the page, but it seems like it keeps adding hidden and display:none to it for some reason. I checked in the inspect window, and it looks like it adds these rules in a generated <style></style> In my source I put this: <img src="{{ advert.image_url }}"> (don't mind the Django tags), while it renders it like this to the page: <img src="/media/image/image.jpg" hidden style="display: none !important;"> It adds this to the html, I did not create any of this myself <style type="text/css"> :root #ads > .dose > .dosesingle { display: none !important; } </style> <style type="text/css">img[src="/media/image/image.jpg"], img[src="image/image.jpg"] {display:none !important;} </style> Anyone knows why this happens to this image only? Its all good for images on other pages, so I'm not sure where this comes from. EDIT: I also tried to override these rules with css/jquery but that did not work unfortunately -
How can I store datas entered in to a registration form in python-django?
I created a login page and a registration form using HTML. Login.html {% load staticfiles %} <html> <head> <title>login_page</title> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"> <link rel="stylesheet" href="{% static 'css/signup.css' %}"> <link href="//fonts.googleapis.com/css?family=Arial&subset=latin,latin-ext" rel="stylesheet" type="text/css"> <link href="//fonts.googleapis.com/css?family=Merienda+One" rel="stylesheet" type="text/css"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <center> <title>Online Registration</title> </head> <script type="text/javascript"> function validate(){ var valid = true; var email = $('#email').val(); var password = $('#password').val(); if(email=='' || email==null) { valid=false; $('#email_error').html("* Please enter email."); } else { $('#email_error').html(""); } if(password=='' || password==null) { valid=false; $('#password_error').html("* Please enter password."); } else { $('#password_error').html(""); } if(valid==false) { return false; } else { alert("You form is ready to submit."); return true; } } </script> <body> <br> <h1><center>Login Form</center></h1> <form action="" method="post" onsubmit="return validate();" id="form_submission_ajax"> <table class="form-table"> {% csrf_token %} <br><br> <tr> <td></td> <td id="f_name_error" class="error"></td> </tr> <tr> <td><label>Email:</label></td> <td><input type="email" name="email" id="email"></td> </tr> <tr> <td></td> <td id="email_error" class="error"></td> </tr> <tr> <td><label>Password:</label></td> <td><input type="password" name="password" id="password"></td> </tr> <tr> <td></td> <td id="password_error" class="error"></td> </tr> <tr> <td></td> <br><br> <td><input type="submit" name="submit" value="Login"></td> <td><a href="{% url 'register' %}">Sign up</a></td> </tr> </form> </html> Registration.html {% load staticfiles %} <html> <head> <title>login_page</title> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"> <link rel="stylesheet" href="{% static 'css/signup.css' %}"> … -
How to get the model column value from the foreign key
I am trying to learn Django and I have a simple model like: class Document(models.Model): labelled_image = models.ForeignKey(LabelModel, db_column='label') So this refers to another model(LabelModel), which is defined as: class LabelModel(models.Model): image = models.FileField(upload_to='documents/label', db_column='path', default='Some Value') Now, at some point I save an instance of a Document model and I get hold of the primary key. So, I can get the model instance by: obj = Document.objects.filter(pk=document_id) Now, my question is how can I get the actual value of the corresponding image in the LabelModel that the foreign key points to? In database pseudocode I would have something like (I have not done this in a while): SELECT path from label_table where id=obj.labelled_image and this would return me the path string from the database. -
Static x-axis with datetime type column
I set my chart's column type to datetime and it has added un-necessary dates with large space in between in the x-axis, and reduced the size of the columns to almost invisible. [screen shot 1]: If I change the column to String type, and replace the data with String, then I get this [screen shot 2]: Is there an option that would exclude the distance associated with time in x-axis? Basically, I want the x-axis to behave as if it was still a string type. I want static distance between the bars and keep the datetime type because I need it to set filters. Anyone has any ideas on how I can achieve this? Thanks -
Can't use {{ form.media }} in django-datetime-widget because my model contain field named "media"
I'm trying to use django-datetime-widget with my ModelForm to show date/time picker. github repo: https://github.com/asaglimbeni/django-datetime-widget I followed instructions up to here: <head> .... <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <link href="{{ STATIC_URL }}css/bootstrap.css" rel="stylesheet" type="text/css"/> <script src="{{ STATIC_URL }}js/bootstrap.js"></script> {{ form.media }} .... </head> But my model have field named "media", which is declared in my models.py like this: media = models.ImageField(blank=True, null=True, upload_to=media_location, default=settings.MEDIA_ROOT + '/images/default_icon.png', storage=FileSystemStorage(location=settings.MEDIA_ROOT)) My 'media' field is used to enable user to upload an image of a product. Problem: When I put {{ form.media }} in <head> tag in template, it just render the image uploader form. Clearly it does not do its job in django-datetime-widget integration. P.S. I'm not sure if renaming the 'media' field will serious break my production website. This 'media' field is used to store 1,000+ important images of my users. Thanks in advance.