Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
how to sort the rows according to the particular column value in python Django
we have a table and we want to print the table according to the status. Status is one of the column name. That status should be ok, unreachable, alert and we want the row whose status is ok that will show on top. so my question is where i have to write the code i.e inside the model.py or view.py . def get_queryset(self, request): qs = self.model._default_manager.get_queryset() order = ['Ok', 'Alert', 'Unreachable'] return sorted(qs, key=lambda x: order[x[status]]) i have wrote this code inside the model.py its not working -
Only one polish letter displayed correctly in xhtml2pdf generated pdf with ISO-8859-2 encoding
I am trying to generate PDF with my data in it. I use xhtml2pdf: def render_to_pdf(template_src, context_dict={}): template = get_template(template_src) html = template.render(context_dict) result = BytesIO() pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-2")), result, encoding='ISO-8859-2') if not pdf.err: return HttpResponse(result.getvalue(), content_type='application/pdf') return None ... elif response.POST.get("print"): context = { "ls": ls_query, "page_product": page_product, } pdf = render_to_pdf("print_zam.html", context) if pdf: response = HttpResponse(pdf, content_type='application/pdf') filename = "Zamówienie_%s.pdf" % ls_query content = "inline; filename=%s" % filename response['Content-Disposition'] = content return response return HttpResponse("Not found") In my template i use <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2"> but the only polish letter that is displayed correctly is Óó, the rest looks like a black square. Where seems to be the issue? -
how can i delete image from file system?
i want to test my api when i test each time create and delete the photo in test database but each time add it for the nth time it add another from that photo to file system so i cant check the result because each time i have another of that photo how i can delete them each time from file system class TestUserAvatar(APITestCase): def setUp(self): user_information() self.user1 = User.objects.first() self.client = APIClient() def test_post_user_avatar(self): self.client.force_login(user=self.user1) with open("/Users/fahime/desktop/download.jpeg", "rb") as fp: response1 = self.client.patch("/api/v1.0.0/accounts/avatar/", {"cover": fp}) -
How to filter an annotated query based on a specific item of the query ,keeping the annotated fields?
I have a table named A.I'm annotating some columns to it and creating a queryset. Now I want to filter this queryset based on one of the records of this table and want to have the correct values of the annotated columns.I don't want the annotated fields to be calculated again. The most important annotated column for me is the row_number column. -
Show fields in admin page only if user has specific rights
I'm working on the Django admin site of an online shop, and I'm asked to enable a refund button only to a limited group of admins. The current situation, extremely simplified, is the following: models.py class ItemOrder(models.Model) [various fields and functions] admin.py class ItemOrderAdmin(admin.ModelAdmin): fieldsets = [ ... ('Actions', {'fields': ['created', 'modified', 'refund_link']}), ] ... readonly_fields = [..., 'created', 'modified', 'refund_link'] [other functions] def refund_link(self, order): ... At the moment every user with the right to see this page can click on the refund link and refund the order. I need to restrict its visibility/usability only to users who have a specific right. I tried with the @permission_required decorator, but the link is unusable for every user (it becomes "-" for anyone, even superusers). I also tried adding the get_form method to the ItemOrderAdmin class, but the refund link disappears completely for every user. This is how it was implemented: admin.py class ItemOrderAdmin(admin.ModelAdmin): fieldsets = [ ... ('Actions', {'fields': ['created', 'modified']}), ] ... readonly_fields = [..., 'created', 'modified', 'refund_link'] def get_form(self, request, obj=None, **kwargs): if request.user.is_superuser: # Will be changed with a more specific right later kwargs['form'] = EventTicketOrderPersonForm return super().get_form(request, obj, **kwargs) [other functions] def refund_link(self, order): ... forms.py … -
Django foreign key JWT auth
In my project I have the Post and Category Model and full working JWT Authentication. class Category(models.Model): name = models.CharField(max_length=255) def __str__(self): return self.name class Post(models.Model): title = models.CharField(max_length=50) content = models.TextField() created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) author = models.ForeignKey(User, on_delete=models.CASCADE) category = models.ManyToManyField(Category, related_name='posts')\ class Category(models.Model): name = models.CharField(max_length=255) def __str__(self): return self.name I want to create a view, that creates a new Post object, in which author will be assigned to Token owner that I pass in authorization (Bearer Token ) postman.image.example. I dont know how to do it please help. Sorry for my english. Serializer class PostSerializer(FlexFieldsModelSerializer): class Meta: model = Post fields = '__all__' read_only_fields = ['id', 'created'] expandable_fields = { 'category': ('blog.CategorySerializer', {'many': True}), 'comments': ('blog.CommentSerializer', {'many': True}), 'images': ('blog.ImageSerializer', {'many': True}), } -
Django get_or_create: aggregation as default
For each day, I need to assign an incremental ID to messages that I receive. Messages can get consumed multiple times, in which case the existing ID should be used if it already exists for the current day. For example: date | message_key | assigned_id 2021-02-02 | A | 1 2021-02-02 | B | 2 2021-02-02 | C | 3 2021-02-02 | A | 1 ... 2021-02-03 | D | 1 2021-02-03 | A | 2 Is there any way I can accomplish this using Django while avoiding race conditions? This is what I currently have, but this is not safe from race conditions: @transaction.atomic def get_message_id(message_key: str): today = datetime.date.today().strftime('%Y-%m-%d') counter, created = Counter.objects.select_for_update().get_or_create( date=today, message_key=message_key, defaults={ "assigned_id": Counter.objects.filter(date=today).aggregate( value=Coalesce(Max("assigned_id") + 1, 1) )["value"] } ) return counter.assigned_id -
I am getting django.core.exceptions.ImproperlyConfigured while trying to setup my django and django channels app with daphne
I am getting Django.core.exceptions.ImproperlyConfigured while trying to setup my Django and Django channels app with daphne. This error only comes when I use Django Simple JWT. raise ImproperlyConfigured( django.core.exceptions.ImproperlyConfigured: Requested setting SIMPLE_JWT, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. -
Django - Do Not send email to admins for HTTP 503 error code
I configured Error reporting for my django app to send emails to admins i specified in ADMINS list in settings.py. it works perfectly well. Based on official django documentation, it will send email whenever a HTTP 500 or greater status code raised: When DEBUG is False, Django will email the users listed in the ADMINS setting whenever your code raises an unhandled exception and results in an internal server error (strictly speaking, for any response with an HTTP status code of 500 or greater). How to override this behaviour? To be specific, i want django to send erros just when HTTP 500 raised. P.S: sometimes i enable maintenance mode in my app, so each request will raise a 503 code for user which is OK. But it will send an error email per request for ADMINS which is NOT OK! -
Make function return predictable values for testing purposes
I need a function to return predictable values when running tests. For example, I have a function get_usd_rates(), which is loading USD forex rates from some API. So far when I was using it inside any other function I was passing rates as an optional argument for testing purposes only. Seems hacky, but it worked. Like this: def some_other_function(rates=None): if rates is None: rates = get_usd_rates() # do something with rates But now I am facing a situation where I can't pass extra argument to a function (private class method for django model, which is called on model field change). Is there a way to make get_usd_rates() function aware that test is running and always return some predefined value without noticeable performance impact in this case? Or what is the best way to deal with this problem. -
Im getting the following error : name 'doctor_id' is not defined
I am trying to get objects from a database onto a webpage but I seem to keep getting the following error. The framework I'm using is Django Error: (it occurs in the views.py incase you were wondering) name 'doctor_id' is not defined The views.py is: from django.shortcuts import render, get_object_or_404 from django.core.mail import send_mail from .models import Doctors def test2(request): doctor = Doctors.objects.all() selected_item2 = get_object_or_404(Doctors, pk=doctor_id) Doctors.doctor = selected_item2 Doctors.save() return render(request, 'website/test2.html', {}) The models.py is: class Doctors(models.Model): dname = models.CharField(max_length=80) ddept = models.CharField(max_length=80) dphone = models.CharField(max_length=80) demail = models.CharField(max_length=80) dimage = models.ImageField(upload_to= 'portfolio/images') -
How do I create a search for a foreignkey in Rest framework? I tried and got "FieldError at /list/ Related Field ...: icontains"
this the serializer with the fields added class ListSerializer(serializers.ModelSerializer): user = serializers.ReadOnlyField(source='user.username') status = serializers.ReadOnlyField(source='status.status') title = serializers.ReadOnlyField(source='title.title') class Meta: model = ListModel fields = ('user', 'title', 'status', 'endDate') my views are below with the codes for the search class ListView(generics.ListAPIView): queryset = ListModel.objects.all() serializer_class = ListSerializer filter_backends = [filters.SearchFilter] search_fields = ['user', 'title', 'status'] def perform_create(self, serializer): serializer.save(user=self.request.user, status=self.request.status, title=self.request.title) my model with the foreign key. the date field is the only field that is not a foreign key class ListModel(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='User', on_delete=models.CASCADE) title = models.ForeignKey(DocxModel, on_delete=models.CASCADE, related_name='topic') status = models.ForeignKey(CatModel, on_delete=models.CASCADE, default="TO DO", name='status') endDate = models.DateField(default=strftime("%Y-%m-%d"), name='endDate') def __str__(self): return str(self.user) -
Django: objects.raw() shows error while working with Postgresql but works fine while using sqlite3 database
My code works fine when I use the sqlite3 DB. But when I use Postgresql as my DB my code throws error column "product_variants.id" must appear in the GROUP BY clause or be used in an aggregate function LINE 1: SELECT * FROM product_variants WHERE product_id=6 GROUP BY... I have made all necessary migrations already. views.py def product_detail(request,id,slug): query = request.GET.get('q') product = Product.objects.get(pk=id) context = {'product': product,} if product.variant !="None": # Product have variants if request.method == 'POST': #if we select color variant_id = request.POST.get('variantid') variant = Variants.objects.get(id=variant_id) #selected product by click color radio colors = Variants.objects.filter(product_id=id,size_id=variant.size_id ) sizes = Variants.objects.raw('SELECT * FROM product_variants WHERE product_id=%s GROUP BY size_id',[id]) # sizes = Variants.objects.filter(product_id=id).values('size_id') print(sizes) query += variant.title+' Size:' +str(variant.size) +' Color:' +str(variant.color) else: variants = Variants.objects.filter(product_id=id) colors = Variants.objects.filter(product_id=id,size_id=variants[0].size_id ) sizes = Variants.objects.raw('SELECT * FROM product_variants WHERE product_id=%s GROUP BY size_id',[id]) # sizes = Variants.objects.filter(product_id=id).values('size_id') print(sizes) variant =Variants.objects.get(id=variants[0].id) context.update({'sizes': sizes, 'colors': colors, 'variant': variant,'query': query }) # print(product.countreview()) return render(request,'eshop/products.html',context) In the above code, I have tried to replace the .raw() query to .filter() (which I later commented out) but still, it doesn't work as I expected; it doesn't show the size details but shows the color details in … -
Django rest framework POST request: JSONDecodeError at /competition-create
Im trying to simply perform a post request that will save a new competition to the database. # views.py class CompetitionCreateView(generics.CreateAPIView): serializer_class = CompetitionSerializer queryset = Competition.objects.all() def create(self, request, *args, **kwargs): serializer = CompetitionSerializer(data=request.data) if serializer.is_valid(): competition = serializer.save() return Response( data=CompetitionSerializer(competition).data, status=status.HTTP_201_CREATED, content_type="json") return Response(data=serializer.errors, status=status.HTTP_400_BAD_REQUEST, content_type="json") # serializer.py class CompetitionSerializer(serializers.ModelSerializer): class Meta: model = Competition fields = "__all__" response: I have tried using regular APIView and switching from def create(...) to def post(...) but no luck. Also tried to parse the request data content to json. -
ManyToManyField save in Django generic View not saving correctly
I have the following code for a Model that has a ManyToManyField in it. SinglePrescriptionFormset = modelformset_factory( PrescriptionLine, form=PrescriptionLineForm, fields='__all__', extra=0, can_delete=True) class PrescriptionForm(forms.ModelForm): class Meta: model = Prescription exclude = ['handed_out', ] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_tag = True self.helper.form_class = 'form-horizontal' self.helper.label_class = 'col-md-3 create-label' self.helper.field_class = 'col-md-9' self.helper.layout = Layout( Div( Field('patient'), Field('note'), HTML('<hr class="style2">'), Fieldset('Add Drug', Formset('line_prescription')), HTML('<hr class="style1">'), ButtonHolder(Submit('submit', 'save')), ) ) def clean(self, *args, **kwargs): cleaned_data = super().clean(*args, **kwargs) print(cleaned_data) # cleaned_data.get('line_prescription') return cleaned_data class PrescriptionCreate(generic.CreateView): model = Prescription template_name = 'doc_aide/write_prescription4.html' form_class = PrescriptionForm def get_context_data(self, **kwargs): print('here') context = super().get_context_data(**kwargs) if self.request.POST: context['line_prescription'] = SinglePrescriptionFormset(self.request.POST) else: context['line_prescription'] = SinglePrescriptionFormset() context['form'].fields['patient'].initial = Patient.objects.get(pk=self.kwargs['patient']) return context def form_valid(self, form): print('Ia am here') context = self.get_context_data() prescriptionlines = context['line_prescription'] with transaction.atomic(): form.instance.created_by = self.request.user self.object = form.save() if prescriptionlines.is_valid(): prescriptionlines.instance = self.object prescriptionlines.save() return super().form_valid(form) def get_success_url(self): return reverse('doc_aide:prescription_detail', kwargs={'pk': self.object.pk}) This kind of works but there is one mistake in it. It saves the same ManyToManyField to all other Prescription Models. Meaning that when I have created one Prescription it saves all correctly. When I save another the ManyToManyFields from the first one are overwritten. New ones are not … -
Query a m2m relation in django
I have a ORM in which there is a m2m relation like this: class FlowKits(models.Model): kit = models.ForeignKey(Kit, on_delete=models.CASCADE) trip_cost = models.IntegerField(default=0) class Flow(models.Model): flow_name = models.CharField(max_length=500, default=0) kits = models.ManyToManyField(FlowKits) How can I get the trip_cost of a Flow whose id = 10 and kit id = 18? I tried the following but it just give me the Flow Object f_obj = Flow.objects.filter(id=10, kits__kit=18) -
Problem of referencing the body content of the Post model using Foreign Key in Newsletter's model
I am trying to send out the email with the Post body instead of HTML file upload default in sendgrid. Therefore, I changed the original code contents = models.FileField(upload_to='uploaded_newsletters/') to contents = models.ForeignKey(Post, on_delete=models.CASCADE, null=True). But I am not sure whether it can access the Post object's body with this code. And after changing it there is an error of 'Post' object has no attribute 'read' when I tried to send the email. I know this is because the code of contents = self.contents.read().decode('utf-8') . Therefore, I would like to ask how can I change these 2 lines of code in order to send out the Post body in an email? Thanks. My Post model: class Post(models.Model): title = models.CharField(max_length=255) body = models.TextField(blank=True, null=True) def __str__(self): return self.title My Newsletter model: class Newsletter(models.Model): subject = models.CharField(max_length=150) contents = models.ForeignKey(Post, on_delete=models.CASCADE, null=True) #here is my problem def __str__(self): return self.subject + " " + self.created_at.strftime("%B %d, %Y") def send(self, request): contents = self.contents.read().decode('utf-8') ##here is my problem too subscribers = Subscriber.objects.filter(confirmed=True) sg = SendGridAPIClient(settings.SENDGRID_API_KEY) for sub in subscribers: message = Mail( from_email=settings.FROM_EMAIL, to_emails=sub.email, subject=self.subject, html_content=contents + ( '<br><a href="{}/delete/?email={}&conf_num={}">Unsubscribe</a>.').format( request.build_absolute_uri('/delete/'), sub.email, sub.conf_num)) sg.send(message) -
DETAIL: Key (sns_login_id)=(1) is not present in table "social_login_platforms" while unit testing with Pytest
I have been trying to implement unit tests with a legacy codebase. So far, I have created simple fixture functions that create Country, User, SocialLoginPlatform objects. I use Pytest and Pytest-Django to run unit tests. However, there seems to be an absence of some data, which I cannot understand since I didn't forget to put the fixture in the testing function. tests.py @pytest.fixture def social_platform(): SocialLoginPlatform.objects.create(name="none") social_platform = mixer.blend(SocialLoginPlatform, name="google") return social_platform @pytest.fixture def country(): country = mixer.blend(Country, name="South Korea", code="KR") return country @pytest.mark.django_db def test_user_creation_user_signup(client, country, social_platform): url = reverse('signup-admin') data = { "company_name": "Random_Company_02", "country_id": 3, "email": "lnrdwd@goreadit.site", "language": "en", "name": "Rand Minit", "password": "12345678" } response = client.post(url, json.dumps(data), content_type='application/json') assert country.id == 3 The test runs fine and passes the test assert country.id == 3 However, as the test tears down the test_db, an error occurs: ====================================== ERRORS ====================================== _______________ ERROR at teardown of test_user_creation_user_signup ________________ self = <django.db.backends.utils.CursorWrapper object at 0x10b4a0d50> sql = 'SET CONSTRAINTS ALL IMMEDIATE', params = None ignored_wrapper_args = (False, {'connection': <django.db.backends.postgresql.base.DatabaseWrapper object at 0x109f84e10>, 'cursor': <django.db.backends.utils.CursorWrapper object at 0x10b4a0d50>}) def _execute(self, sql, params, *ignored_wrapper_args): self.db.validate_no_broken_transaction() with self.db.wrap_database_errors: if params is None: # params default might be backend specific. > return self.cursor.execute(sql) … -
The best way to do an efficient filter query in django
models.py file I am not so good at this aspect in Django. Please can someone help me? I wish to know if there is a more efficient way for the class method already_voted class Vote(TimeStamped): voter = models.ForeignKey(get_user_model(), verbose_name=_("Vote"), on_delete=models.CASCADE) contester = models.ForeignKey(Contester, verbose_name=_("Contester"), on_delete=models.CASCADE, help_text=("The chosen contester"), related_name="votes") ip_address = models.GenericIPAddressField( _("Voter's IP"), protocol="both", unpack_ipv4=False, default="None", unique=True ) num_vote = models.PositiveIntegerField(_("Vote"), default=0) class Meta: unique_together = ('voter','contester') verbose_name = _("Vote") verbose_name_plural = _("Votes") permissions = ( ("vote_multiple_times", "can vote multiple times"), ) .... .... @classmethod def already_voted(cls, contester_id, voter_id=None, ip_addr=None): return cls.objects.filter(contester_id=contester_id).exists() and \ (cls.objects.filter(ip_address=ip_addr).exists() or \ cls.objects.filter(voter_id=voter_id).exists()) -
Django Search Vector throws Mysql error when Postgresql is configured
I'm getting an error when using a Search Vector with Django. The weird things is that the error tells me the query on the MySQL database is incorrect, when I'm using PostgreSQL. I have no clue what's wrong. As I'm using the Search Vector from the postgres contrib module. Django behaves unexpected, how can I solve this error? Error in the browser: Environment: Request Method: POST Request URL: http://test.shop4raad.nl:8000/blog/search/post Django Version: 3.1.2 Python Version: 3.6.9 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', 'django.contrib.sitemaps', 'django.contrib.postgres', 'taggit', 'blog.apps.BlogConfig'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware'] Template error: In template /home/maarten/test/blogexperiment/project/project/templates/base.html, error at line 0 1064 1 : <!DOCTYPE html> 2 : {% load custom_tags %} 3 : {% load static %} 4 : <html lang="en"> 5 : <head> 6 : <title>{% block title %}{% endblock %}</title> 7 : <link href="{% static 'styles/blog.css' %}" rel="stylesheet"> 8 : </head> 9 : <body> 10 : <div id="content"> Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 84, in _execute return self.cursor.execute(sql, params) File "/usr/local/lib/python3.6/dist-packages/django/db/backends/mysql/base.py", line 73, in execute return self.cursor.execute(query, args) File "/usr/local/lib/python3.6/dist-packages/MySQLdb/cursors.py", line 206, in execute res = self._query(query) File "/usr/local/lib/python3.6/dist-packages/MySQLdb/cursors.py", line 319, in _query db.query(q) File "/usr/local/lib/python3.6/dist-packages/MySQLdb/connections.py", line 259, in … -
Decimal numbers in views.py
I am new to Python/Django, so please bear with me! I have simple django views to sum book values: def portfoyozet(request): librarysum = textshare.objects.filter(user_id=request.user.id).aggregate(Sum('bookvalue'))['bookvalue__sum'] or 0 return render(request, 'todo/libsum.html', {'librarysum': librarysum,}) Which is working perfectly but result isn't show decimal values. 4800,30 becomes 4800,00 I dont need to round or something like that here. I just need to show all values with decimal values.It strikes as a fairly common thing to do but I can't figure out which filter I'm supposed to use. Also found something while googling and change my views.py like: def portfoyozet(request): librarysum = textshare.objects.filter(user_id=request.user.id).aggregate(Sum('bookvalue'))['bookvalue__sum',0.00] or 0 return render(request, 'todo/libsum.html', {'librarysum': librarysum,}) But it doesnt work either. I have to seek help here as a last resort. I really appreciate if someone could help me out. Thank you in advance. -
django template if return True even if variable False
I am beginner in django and most probably i do something wrong. My view : class StartPageIndexView(View): def get(self, request): form = UserLoginRegistrationForm() lorem_ipsum_text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." print("request.user %s", request.user) is_logged_on = False if request.user.is_authenticated: logger.error("User authenticated") is_logged_on = True context = { 'lorem_ipsum': lorem_ipsum_text, 'registration_form': form, 'is_logged_on': is_logged_on, } return render(request, 'startpage/index.html', context=context) my template : {% extends "base.html" %} {% if is_logged_on is True %} {% block sidebar %} {{ is_logged_on }} {% include "inc/_sidebar.html" %} {% endblock %} {% endif %} {% block content %} {{ is_logged_on }} {{ lorem_ipsum }} {% endblock %} In browser i see this . Can you please tell me what i do … -
django.core.exceptions.ImproperlyConfigured: Boardapi_update is missing a QuerySet
Boardapi_update is missing a QuerySet. Define Boardapi_update.model, Boardapi_update.queryset, or override Boardapi_update.get_queryset(). This error occurs. The same error occurred with boardapi_delete. help me!!!!!!!!!!! views.py class Boardapi_update(generic.UpdateView): def update(self, request, *args, **kwargs): pk = { 'pk': self.kwargs['pk'], } data = { 'b_title': requests.POST.get['b_title'], 'b_note': requests.POST.get['b_note'] } url = 'http://localhost:8080/boardapi/'+str(pk['pk'])+'/update/' bupdate = requests.put(url, data=data) print(bupdate) def get_success_url(self): return reverse('board_detail', kwargs={'pk': self.object.board.pk}) class Boardapi_delete(generic.DeleteView): def delete(self, request, *args, **kwargs): datas = { 'pk': self.kwargs['pk'] } url = 'http://127.0.0.1:8080/boardapi/'+str(datas['pk'])+'/delete/' bdelete = requests.delete(url, params=datas) print(bdelete) return redirect(reverse('board')) -
Django Embeded model formset and model form
I'm a newbie in Django. I want to know how to embed multiple model forms and formsets ? how to set default or remove fields based on user permission and insert them into one form and get data from users and update/create objects in multiple model? what views method should I use? class-based views or function-based views? below there is an example of what I want to do. if you need more information please let me know this is a report view that will show the detail of the report that the user sent to the website and the admin can change/update/delete status and looted game items of the report and save it each report belongs to one user and one game account. and each looted game item belongs to a report, user, and game account. sample of my form and there is my models: class GameAccounts(models.Model): name = models.CharField(null=True,blank=True,max_length=400) provider = models.IntegerField(choices=GAME_PROVIDER, null=True) game = models.IntegerField(choices=GAME_NAME, null=True) username = models.CharField(null=True,blank=True,max_length=400) password = models.CharField(null=True,blank=True,max_length=400) def __str__(self): return self.name class GameAccountsHistory(models.Model): gameaccounts = models.ForeignKey(GameAccounts, on_delete=models.CASCADE, ) user = models.ForeignKey(User,on_delete=models.CASCADE,) date_stamp = models.DateField(auto_now=True,null=True) time_stamp = models.DateTimeField(auto_now=True,null=True,blank=True) status = models.IntegerField(choices=GAME_STATUS, null=True) class LootedGameItem(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE, ) gameaccounts = models.ForeignKey(GameAccounts, on_delete=models.CASCADE, ) … -
Klaviyo - Removed download button from image, how can I remove mouse over events?
With this variable {{ emptyURL|add:"#" }} I removed the download button from my image (small download button that appears in bottom right corner when you hover over the image) but when you hover with mouse the pointer becomes hand, how to stop that from happening?