Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Issue using Django api for bulk creating and updating records by csv
New to django and working on bulk creating and updating rows in my database using csv. I am using this: Https://pypi.org/project/django-bulk-update-or-create/#description I can get the first option: bulk_update_or_create working fine but when I use the bulk option: bulk_update_or_create_context it uploads data into my database but as numbers only (example below) - I am missing something really obvious here but I cannot figure it out. I would be expecting data like this for example (and its what I get using the first option bulk_update_or_create: vsim_iccid - 8997103118112597732F (pk) country_or_region - AE_UNITED ARAB EMIRATES operator - DU vsim_imsi - 424030246932624 online_country - AE sim_status - Enable, plmn_set - 42403 package1 - UAE 50 package2 - blank instead I get this when I use the bulk option bulk_update_or_create_context: vsim_iccid - 1 country_or_region - 21 vsim_imsi - 21 online_country - 21 sim_status - 21 plmn_set - 21 package1 - 21 package2 - 21 code: def upload_vsim_mgmt(request): form = CsvModelForm(request.POST or None, request.FILES or None) if form.is_valid(): form.save() form = CsvModelForm() obj = Csv.objects.get(activated=False) with open(obj.file_name.path, 'r') as f: df = pd.read_csv(f, encoding='latin1', error_bad_lines=False, index_col=False, dtype='unicode', sep=',').replace(np.nan, '', regex=True).replace("\t", '', regex=True) #print(df) row_iter = df.iterrows() items = [ VSIMData( country_or_region=row['Country or Region '], operator=row['Operator '], … -
How can I parse a field parameter using taggit custom tags?
Having in my project two apps that use tags, I wanted in my admin area to have these two groups of tags separated, so I followed the instructions of this thread. However I get a FieldError and a message: Cannot resolve keyword 'None' into field. Choices are: blogtags, id, name, post, slug. As it seems I have to parse 'blogtags' field as a parameter, but my poor experience in Django doesn't allow me to understand in which method do I have to do that. Any help is greatly appreciated. my models.py for the one of the two apps: from django.db import models from django.utils import timezone from django.contrib.auth.models import User from django.urls import reverse from ckeditor_uploader.fields import RichTextUploadingField from django.utils.text import slugify from taggit.managers import TaggableManager from taggit.models import TagBase, GenericTaggedItemBase class Category(models.Model): name = models.CharField(max_length=100, unique=True, primary_key=True) def __str__(self): return self.name class BlTagged(TagBase): class Meta: verbose_name = "Blog Tag" verbose_name_plural = "Blog Tags" class BlogTags(GenericTaggedItemBase): tag = models.ForeignKey(BlTagged, on_delete=models.CASCADE ) class Post(models.Model): title = models.CharField(max_length=100) content = RichTextUploadingField(blank=True, null=True, external_plugin_resources=[( 'youtube', '/static/vendor/ckeditor_plugins/youtube/youtube/', 'plugin.js', )]) date_posted = models.DateTimeField(default=timezone.now) author = models.ForeignKey(User, on_delete=models.CASCADE) is_published = models.BooleanField(default=True) slug = models.SlugField(unique=True, max_length=100, allow_unicode=True) category = models.ForeignKey('Category', default='uncategorized', on_delete=models.SET_DEFAULT, null=True) blogtags = TaggableManager(blank=True, through=BlogTags) … -
ValueError at /admin/login/ samesite must be "lax" or "strict"
Help, i'm new doing this :( i don't know how to solve this Error. I don't know how to solve this error that it throws at me in the browser. In Terminal, my project runs fine, but I don't know why that error appears in the browser :(. P.S. The project is already "working", it is in the process of improvements and I just cloned it from github to start adding changes. -
Getting UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte in Django unit test
I have a unit test where I want to test the post method of my view (which is a GenericViewSet) I want to be able to up load files in this post request. So I have this code: photo2 = SimpleUploadedFile(name='test_image.jpg', content=open(image_path, 'rb').read(), content_type='image/jpeg') data = { 'foo_uid': foo_uid, 'bazz': 'bazz', 'photos': [{'photo': photo2, 'comment': 'pic of cats'}] } response = self.client.post(path=url, data=data, format="json") When the code runs the self.client.post() raises this error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte I have seen a lot of answers for this question and they say to use open(..., 'rb') to read the file as binary. Well I am doing that but I still get this error. Thanks -
Can you please explain what is happening in this simple django function? formset=OrderFormSet(request.POST,instance=customer)
I am a beginner to django so I am trying to grasp the basic concepts...what happens at the formset=OrderFormSet(request.POST,instance=customer)? Does the formset get filled with some request.POST data? Does it get sent to server?Why is there the request.POST? def createOrder(request, pk): OrderFormSet = inlineformset_factory(Customer, Order, fields = ('product','status'), extra=10) customer=Customer.objects.get(id=pk) formset=OrderFormSet(queryset=Order.objects.none(),instance=customer) if request.method=='POST': formset=OrderFormSet(request.POST,instance=customer) if formset.is_valid(): formset.save() return redirect('/') context={'formset':formset} return render(request, 'accounts/order_form2.html',context) -
Redirect User After Login in Django
I am trying to implement my login page, so it can redirect to specific page in the websites. When the user click on the Login, it check if the user is staff, then send the user to admin page, not user then stay at login, if regular user, then send to regular user page. I haven't completed the LoginView yet because I just want to see if it can direct to admin page after login. I have researched online and tried many different way, but I couldn't figure out how to do so. What should I change or add in the urls.py or LOGIN_URL/LOGIN_REDIRECT_URL. Thank you! url.py urlpatterns = [ path('admin/', admin.site.urls), path('', views.index, name='index'), path('output/', views.output, name="output"), path('default_crawler/', views.default_page, name="default_page"), path('admin_page/', views.admin_page, name="admin_page"), path('regular_page/', views.regular_page, name="regular_page"), path('pass_forgot/', views.pass_forgot, name="pass_forgot"), path('pass_change/', views.pass_change, name="pass_change"), path('pass_change_success/', views.pass_change_success, name="pass_change_success"), path('pass_found/', views.pass_found, name="pass_found"), path('register/', user_views.register, name="register"), path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'), ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) views.py def LoginView(request): if request.method == 'POST': form = AuthenticationForm(request, request.POST) if form.is_valid(): username = form.cleaned_data.get('username') password = form.cleaned_data.get('password') user = authenticate(username=username, password=password) if user.is_staff: login(request, user) return redirect('admin_page') else: messages.error(request, "Invalid username or password") else: messages.error(request, "Invalid username or password") form = AuthenticationForm() return render(request, 'users/login.html', {'form': form}) settings.py LOGIN_URL … -
Displaying cards inside a responsive container with a grid of 3x3 initially
I'm trying with bootstrap and django to list cards inside a responsive container which in xl screen displays as a 3x3 grid container, has a scrollable overflow, and decreases according to device width. I tried to achieve this at first by wrapping the cards with a flex container with column-layout, but that's only a temporary and undesired solution, also i thought about rearranging cards through javascript upon window-resizing (but that's not optimal), or ... in other way using other techs like css-grid (which i don't know anything about how it works right now). So, what would be the best approach for this... Here i leave you guys a model i drew for this ocassion and serves as an explanatory to the main problem. CODE HERE JUST SERVES AS A TOOL FOR BETTER UNDERSTANDING... BUT IT'S NOT CRUCIAL: i have here one card.... let's say i put 12 instead. HTML <div class="card"> <div class="card-body"> <div class="card-img"> <img src="{% static 'library/img/attention.jpg' %}" class="history-img" alt=""> </div> <h6 class="card-subtitle"> Lorem ipsum dolor sit amet, co </h6> </div> <div class="card-footer"> <span class=""><i class="fas fa-eye"></i>4093</span> <span class=""><i class="fas fa-thumbs-up"></i>1234</span> <span class="badge bg-primary rounded-pill px-2">#hello_there</span> </div> </div> </div> </div> CSS body * { box-sizing: border-box !important; } … -
Django 3.0.7 - No Changes Detected after making Changes to Model
I am making changes to a model AppContactCnt to add new fields to handle deleting of records. Here is that models.py class AppContactCnt(models.Model): id_cnt = models.AutoField(primary_key=True) # idcst_cnt = models.IntegerField() idcst_cnt = models.ForeignKey(AppCustomerCst, models.DO_NOTHING, db_column='idcst_cnt') idctp_cnt = models.ForeignKey(AppContactTypeCtp, models.DO_NOTHING, db_column='idctp_cnt') idtrp_cnt = models.IntegerField() name_cnt = models.CharField(max_length=50) phone_cnt = models.CharField(max_length=50, blank=True, null=True) email_cnt = models.CharField(max_length=100, blank=True, null=True) note_cnt = models.CharField(max_length=100, blank=True, null=True) receives_emails_cnt = models.BooleanField(blank=True, null=True) deleted_cnt = models.BooleanField(blank=True, null=True) # date_deleted_cnt = models.DateTimeField(blank=True, null=True) # deleted_by_cnt = models.CharField(max_length=100, blank=True, null=True) class Meta: db_table = 'app_contact_cnt' app_label = 'easytrade20' I tried to add in managed = True no change. Also tried the following: Delete all previous migration files and pycache files except init. python manage.py migrate --fake-initial python manage.py makemigrations python manage.py migrate I am still getting No changes detected I am not sure how to proceed, any assistance is apprecaited. -
ManagementForm data is missing or has been tampered with though management_form has been included and all the errors for formset have been handled
I am trying to submit formset in django but it is giving me this error: ManagementForm data is missing or has been tampered with Though I have included management_form and have handled all the errors for formset. So, what will be the solution here?Any help will be highly appreciated. I have provided model class, form class, formset, view class and form.html. class GovernmentHoliday(models.Model): day = models.CharField(max_length=128, blank=False) date = models.DateField() holiday_name = models.CharField(max_length=128, blank=False) type = models.CharField(max_length=128, blank=False) comments = models.CharField(max_length=128, blank=False) from django import forms from django.forms import modelformset_factory class GovernmentHolidayForm(forms.ModelForm): """ """ class Meta: model = GovernmentHoliday fields = [ 'day', 'date', 'holiday_name', 'type', 'comments', ] widgets = { 'day': forms.TextInput(attrs={'class': 'form-control form-control-sm'}), 'date': forms.DateInput(attrs={'class': 'form-control form-control-sm has-feedback-left single_cal', 'id': 'single_cal3'}, format='%m/%d/%Y'), 'holiday_name': forms.TextInput(attrs={'class': 'form-control form-control-sm'}), 'type': forms.TextInput(attrs={'class': 'form-control form-control-sm'}), 'comments': forms.TextInput(attrs={'class': 'form-control form-control-sm'}), } def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Edit label # Non required fields # Remove help suggestion for fieldname in ['day', 'date', 'holiday_name', 'type', 'comments']: self.fields[fieldname].help_text = None GovernmentHolidayFormset = modelformset_factory(GovernmentHoliday, fields=('day', 'date', 'holiday_name', 'type', 'comments'), form=GovernmentHolidayForm, extra=0, min_num=1, can_delete = True, can_order = True, ) class GovernmentHolidayAddView(LoginRequiredMixin, CreateView): login_url = '/authentication/login/' template_name = 'leave/government_holiday_add_form.html' government_holiday_formset_class = GovernmentHolidayFormset # Override default get method … -
Prevent react router from pinging Django server
so I have app in React with Router and Django on backend. I have Dashboard component, where I send request to Django for getting posts. But when I go on /dashboard, via Link or URL in browser, I get two requests on server: GET /dashboard GET /posts Why I'm having this /dashboard request and how to stop react for pinging django with this request? Router look like this: <Router history={history}> <Switch> <Route exact path={urls.get('dashboard')}> <Dashboard/> </Route> ... </Switch> -
Django - Pivoting Data without using pivot function
I need to transform rows into columns adding up 'amount' in MONTH/YEAR. My models: class Category(models.Model): title = models.CharField(max_length=25) *Data from model:* {'id': 1, 'title': 'HOUSING'} {'id': 2, 'title': 'FOOD'} class ExpenseType(models.Model): title = models.CharField(max_length=25) category = models.ForeignKey(Category, on_delete=models.CASCADE) *Data from model:* {'id': 1, 'title': 'RENT', 'category_id': 1} {'id': 2, 'title': 'MEALS', 'category_id': 2} class Expense(models.Model): expenseType = models.ForeignKey(ExpenseType, on_delete=models.CASCADE) amount = models.FloatField() date = models.DateField() *Data from model:* {'id': 1, 'expenseType_id': 1, 'amount': 1000.0, 'date': datetime.date(2020, 5, 1)} {'id': 2, 'expenseType_id': 1, 'amount': 1000.0, 'date': datetime.date(2020, 6, 1)} {'id': 3, 'expenseType_id': 2, 'amount': 100.0, 'date': datetime.date(2020, 4, 1)} {'id': 4, 'expenseType_id': 2, 'amount': 200.0, 'date': datetime.date(2020, 4, 1)} The output I need to render: CATEGORY | 04/2020 | 05/2020 | 06/2020 HOUSING | None | 1000.0 | 1000.0 FOOD | 300.0 | None | None Extracting month/year from date Aggregating categorie's amounts by month/year I'm looking for a solution other than pivot or pandas so I can render as for loops and use it with bootstraps dataTables. -
What is 'instance=' and 'queryset=' in django?
what does it do in this function, what does it mean generally? def createOrder(request, pk): OrderFormSet = inlineformset_factory(Customer, Order, fields = ('product','status'), extra=10) customer=Customer.objects.get(id=pk) formset=OrderFormSet(queryset=Order.objects.none(),instance=customer) if request.method=='POST': formset=OrderFormSet(request.POST,instance=customer) if formset.is_valid(): formset.save() return redirect('/') context={'formset':formset} return render(request, 'accounts/order_form2.html',context) -
In django, is it possible to sort the admin page using a function (cannot be written with query expressions) without using raw SQL?
I have this admin page class: class UserAdmin(admin.ModelAdmin): levelfunc = lambda usr: dox_user(usr).rank.level list_display = ('name', levelfunc) My ultimate goal is to be able to sort the admin page using the levelfunc column, sadly django won't allow that. I tried googling a lot and most of the times it said to use a query expression which I cant in this situation because the dox_user function which returns data about the user cannot be simplified to an SQL expression and I can't move the dox_user function to anywhere else because I'll need to rewrite a lot of code if I do that. Is there even a simple way to just sort it by the user's level? -
NoReverseMatch at /signup/ - Reverse for '<WSGIRequest: POST '/signup/'>' not found
The porject I am working on is the blogging website and I am stuck at this signup process, I want it to function like after signup, the user lands on the home page, but instead this is showing me the above error views.py: def handleSignup(request): if request.method == 'POST': username = request.POST['username'] fname = request.POST['fname'] lname = request.POST['lname'] email = request.POST['email'] pass1 = request.POST['pass1'] pass2 = request.POST['pass2'] # creating users myuser = User.objects.create_user(username, email, pass1) myuser.first_name = fname myuser.last_name = lname myuser.save() messages.success(request, 'your account have been successfully created!') return redirect(request, "/home.html") else: return HttpResponse("error 404 not found") urls.py: urlpatterns = [ path("", views.home, name="home"), path("contact/", views.contact, name="contact"), path("about", views.about, name="about"), path("signup/", views.handleSignup, name="handleSignup"), ] forms in base.html: <form action="/signup/" method="post"> <div class="form-group"> <label for="username">Username</label> <input type="text" class="form-control" id="username" name = 'username' placeholder="choose a unique username"> </div> <div class="form-group"> <label for="fname">Firstname</label> <input type="text" class="form-control" id="fname" name = 'fname' placeholder="First Name"> </div> <div class="form-group"> <label for="lname">Lastname</label> <input type="text" class="form-control" id="lname" name= 'lname' placeholder="Last Name"> </div> <div class="form-group"> <label for="email">Email</label> <input type="email" class="form-control" id="email" name = 'email' placeholder="email@example.com"> </div> <div class="form-group"> <label for="pass1">Choose Password</label> <input type="password" class="form-control" name = 'pass1' id="pass1"> </div> <div class="form-group"> <label for="pass2">Confirm password</label> <input type="password" class="form-control" name = … -
How to change CSS properties from within django HTML template logic
Newbie question I presume: How do I change some CSS property (// change background image of parent div) of the parent element from within the logic in the HTML template? Do I really need to implement JS for this? <div class="exercise-items-wrapper"> {% if error %} {{ error }} {% else %} {% for x in exercise %} <div class="exercise-item"> {{x.name}} {% if x.primary_focus == 'CO' %} // change background image of parent div {% endif %} {% if x.friend_verified %} <img src="{% static 'main/images/fv.svg' %}" height="14px"> {% endif %} <p id="exercise-level" class="exercise-level">lv. VII</p> {% if x.video_verified %} <img src="{% static 'main/images/vv.svg' %}" height="14px"> {% endif %} </div> {% endfor %} {% endif %} </div> -
Django templates - How to expand related record data instead of record id when assigning to JS variable?
Some code: models.py class User(models.Model): name = models.CharField(max_length=60) group = models.ForeignKey(Group, on_delete=models.CASCADE) views.py users = User.objects.all() # sent to template template.html let users = jQuery.parseJSON('{{ users|jsonify|safe }}') tags.py @register.filter(is_safe=True) def jsonify(obj): if isinstance(obj, QuerySet): return serialize('json', obj) return json.dumps(obj) This going to assign objects where group field is id number of record in Group model. I need to get all data of this record. How to expand this data? -
Display multiple dynamic object with for loops in templates
So to summary, my database structure is like this: test |_ question |_ choice |_ choice |_ choice |_ question |_ choice |_ choice |_ choice Now I want to display all of the choices of each question on a single page. My views.py: def index(request): data = { 'greeting': 'Welcome User!', 'form_test': forms.TestForm, 'form_question': forms.QuestionForm, 'form_choice': forms.ChoiceForm, 'test': models.Test.objects.get(pk=1), 'questions': models.Question.objects.filter(test_id__exact=1), } questions = models.Question.objects.filter(test_id=1) for question in questions: data['choices_{}'.format(question.id)] = models.Choice.objects.filter(question_id=question.id) print(data) return render(request, 'et_app/index.html', context=data) So technically if I have 2 questions, my data would look something like this: { ... 'choices_1': ... 'choices_2': ... ... } Now, my problem is on displaying these choices on the templates. I tried: {% for question in questions %} <h4>Q: {{ question.content }}</h4> <p>Choices:</p> <ul class="list-group"> {% for choice in 'choices_{}'.format(question.id) %} <li class="list-group-item">{{ choice.content }}</li> {% endfor %} </ul> {% endfor %} It just broke the whole thing. I'm relatively new to Django so forgive my naiveness. How can I fix this? Thanks a lot! -
Use a scan device with django
How is the best native way to scan an image using a device? Im working on web project with Django. I just googled and as far as i know there is a way to get this done with html5 and getusermedia() api. Thanks in Advance, -
Django Page not found with post request
So I am new to Django and I'm trying to create a HTML form (just following the tutorial for the name input) and I can input the name but can't direct to the /thanks.html page. $ views.py from django.http import HttpResponseRedirect from django.shortcuts import render from .forms import NameForm def get_name(request): # if this is a POST request we need to process the form data if request.method == 'POST': # create a form instance and populate it with data from the request: form = NameForm(request.POST) print(form) # check whether it's valid: if form.is_valid(): # process the data in form.cleaned_data as required # ... # redirect to a new URL: return HttpResponseRedirect('/polls/thanks.html') # if a GET (or any other method) we'll create a blank form else: form = NameForm() return render(request, 'name.html', {'form': form}) $ name.html <html> <form action="/polls/thanks.html" method="post"> {% csrf_token %} {{ form }} <input type="submit" value="Submit"> </form> <html> $ /mysite/urls from django.contrib import admin from django.urls import include, path urlpatterns = [ path('polls/', include('polls.urls')), path('admin/', admin.site.urls), ] $ mysite/polls/urls.py from django.urls import path from polls import views urlpatterns = [ path('', views.get_name, name='index'), ] When I go to to the page, I can enter my name fine but … -
Django form is not showing is not generating in html template
I am using django.contrib.auth.views.LoginView for views and here are my files html <form method="GET"> {% csrf_token %} {{ formlog|crispy }} </form> views.py def index(request): formlog = auth_views.LoginView.as_view() if request.method == 'POST': form = UserRegisterForm(request.POST) if form.is_valid(): form.supervalid() form.save() username = form.cleaned_data.get('username') messages.success(request, f'Dear {username} you have been created a new accound!') return redirect('main') else: form = UserRegisterForm() return render(request, 'main/index.html', {'form': form, 'formlog': formlog}) forms.py from django import forms from django.contrib.auth.models import User from django.contrib.auth.forms import UserCreationForm class UserRegisterForm(UserCreationForm): email = forms.EmailField() name_and_surname = forms.CharField(min_length=5, max_length=30) def supervalid(self): expr_a = User.objects.filter(name_and_surname=self.cleaned_data['name_and_surname']).exists() expr_b = User.objects.filter(email=self.cleaned_data['email']).exists() if expr_b: raise ValidatioError(f'There already exists user with that email, use another one ;)') if expr_a: raise ValidatioError(f'This name is already used, sorry') class Meta: model = User fields = ['username', 'email', 'password1', 'password2'] please help istead of talking about things that dont metter. Thanks for help ;) -
Django doesn't load static file and throws error although syntax is correct - is VS Code the culprit?
I have been working with Django for a few days and I'm trying to get the hang of static files and how to integrate them in my project. I have the following code: <div class="background_image" style="background-image: url({% static 'images/home_slider.jpg' %});"> </div> And Python throws this error for this specific block of code: I have more than 30 cases in the same file where I used this pattern {% static 'something' %} and it works in all cases. The only difference between these cases in the one above (that's not working) is that the one above is the only one where I apply the style directly on the HTML tag. I am am my wits' end. From what I researched, the syntax seems to be correct for adding a background image directly in HTML so I'm starting to believe that the error is caused by the fact that VS code is formatting my code in a super weird way when saving and I get something like: <div class="background_image" style=" background-image: url({%static'images/home_slider.jpg'%}); " ></div> Any suggestion would be appreciated. Thank you. -
ValueError at /signup/ The given username must be set
so basically I have been building this blogging website and now I am stuck at this point of the Signup process, the whole work is done using django views.py: def handleSignup(request): if request.method == 'POST': # getting user parameters username = request.POST.get('username') fname = request.POST.get('fname') lname = request.POST.get('lname') email = request.POST.get('email') pass1 = request.POST.get('pass1') pass2 = request.POST.get('pass2') # fname = request.POST['fname'] # lname = request.POST['lname'] # email = request.POST['email'] # pass1 = request.POST['pass1'] # pass2 = request.POST['pass2'] # creating users myuser = User.objects.create_user(username = username, email = email, password = pass1) myuser.first_name = fname myuser.last_name = lname myuser.save() messages.success(request, 'your account have been successfully created!') return redirect(request, 'home') else: return HttpResponse("error 404 not found") form in base.html: <form action="/signup/" method="post"> <div class="form-group"> <label for="username">Username</label> <input type="text" class="form-control" id="username" placeholder="choose a unique username"> </div> <div class="form-group"> <label for="fname">Firstname</label> <input type="text" class="form-control" id="fname" placeholder="First Name"> </div> <div class="form-group"> <label for="lname">Lastname</label> <input type="text" class="form-control" id="lname" placeholder="Last Name"> </div> <div class="form-group"> <label for="email">Email</label> <input type="email" class="form-control" id="email" placeholder="email@example.com"> </div> <div class="form-group"> <label for="pass1">Choose Password</label> <input type="password" class="form-control" id="pass1"> </div> <div class="form-group"> <label for="pass2">Confirm password</label> <input type="password" class="form-control" id="pass2"> </div> {% csrf_token %} <button type="submit" class="btn btn-primary">Submit</button> </form> now I am getting this error: ValueError … -
Django path in admin absolute instead relative
In my admin project i have a situation like this: settings.py: STATIC_URL = '/myproject/static/' models.py: class v_candidatura(models.Model): ... c_cv = models.FileField(upload_to='myproject/static/docs', max_length=254, validators=[FileExtensionValidator(['pdf']),validate_fsize], verbose_name="CV") .... admin.py: class vcandidaturaAdmin(admin.ModelAdmin): list_filter = ('c_mansione',) list_display = ('c_data', 'c_sur', 'c_name', 'c_dob', 'c_en', 'c_de', 'c_cv') ordering = ('-c_data',) admin.site.register(v_candidatura, vcandidaturaAdmin) Now if i log into admin site and go to the 127.0.0.1:8000/admin/myapp/v_candidatura/ and click on c_cv link Django atach begore c_cv link the wole path 127.0.0.1:8000/admin/myapp/v_candidatura/, how can i define my href link for ahref in django admin site? for example i would clicking on my c_cv django admin list field open 127.0.0.1:8000/<c_cv path> So many thanks in advance admin.py -
django ecommerce communication
I am building an e-commerce app for fast food company using Django. There will be a dash-board based on Django admin that will give the vendor control over activating offers or closing shop etc. What I am trying to implement is that once the customer places the order and a message flashes for the vendor to accept or reject. I am not sure what I will need to use to implement that two-way communication between the customer and the vendor admin. Any ideas or alternatives will be very helpful. Thanks -
How to setup carousel slider in Django with records?
I am trying to implement carousel slider in my website, I have ForeignKey relation between Project and Image, I have multiple image store in Image model. It Means that a project can have multiple images, and i want to display those project images in slider, Please let me know how I can display the images in slider, Because currently my images are coming in vertical format. Here is my index.html code, here i am trying to display all images in slider, but it's not working, Please check my code and solve my issue. <div id="carousel-thumb" class="carousel slide carousel-fade carousel-thumbnails list-gallery pt-2" data-ride="carousel"> <!--Slides--> <div class="carousel-inner" role="listbox"> {% for i in project.projectimage.all %} <div class="carousel-item active"> <img class="d-block w-100" src="{{i.project_image.url}}" alt="slide" style="height: 420px;"> </div> {% endfor %} </div> <!--Controls starts--> <a class="carousel-control-prev" href="#carousel-thumb" role="button" data-slide="prev"> <span class="lnr lnr-arrow-left" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" href="#carousel-thumb" role="button" data-slide="next"> <span class="lnr lnr-arrow-right" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div>