Posts by Regis Santos • 1,574 points
70 posts
- 
		1 votes0 answers153 viewsQ: Pandas Dataframe to_html or iterate over the data in the template?Actually I wanted to iterate on the data in the template? But how do I play my pivot’s dice in context and treat them in the template? df = pd.DataFrame(data) pv = df.pivot(index='cands',… 
- 
		0 votes1 answer188 viewsQ: Inserting data-id and data-url into the Datatable extra fieldLook at this code https://github.com/rg3915/frontend/blob/master/djfront/djbasic/templates/djbasic/customer_list_datatable.html#L53 defaultContent: '<i class="fa fa-close pull-right… front-endasked Regis Santos 1,574
- 
		1 votes1 answer87 viewsQ: Transforming clicks into JS functionI’m trying to turn my clicks into functions, since the code is repeating itself in https://github.com/rg3915/fs2w/blob/gh-pages/js/main.js This is the original code: $("#div1").click(function() {… 
- 
		0 votes1 answer64 viewsA: Activating virtualenv in MakefileActivate bash by creating an alias on .bashrc. makefileanswered Regis Santos 1,574
- 
		0 votes1 answer62 viewsA: Grouping only by Manytomany’s first item in DjangoSolved. def books_list(self): count = {} for item in Author.objects.all(): first_book = item.books.first() if first_book: count[first_book] = count.get(first_book, 0) + 1 return count… 
- 
		0 votes1 answer80 viewsA: Django-import-export outside AdminSolved: def export_data_person(request): queryset = Person.objects.all() return _export_data(queryset, 'person') def export_data_person_blocked(request): queryset =… djangoanswered Regis Santos 1,574
- 
		0 votes1 answer95 viewsQ: Changing the place templates (Django)I was trying to leave the templates folder (main) out of the 'core' folder because I actually wanted to leave the 'templates' and 'Static' folder out of the 'core' folder'. Check out my project on… 
- 
		3 votes2 answers147 viewsQ: Filter with first item of a Manytomany DjangoI have it in my template: {% for j in jobs %} <tbody> {% if j.background.all.0.active == False %} ... Hence I need to filter the view similar to this. I tried to jobs =… djangoasked Regis Santos 1,574
- 
		0 votes1 answer80 viewsQ: Django-import-export outside AdminDoes anyone know how I would use the Django-import-export outside the Admin? That is, I wanted the button to export this library in a template of mine, outside of Admin. Which way to the stones? I… djangoasked Regis Santos 1,574
- 
		0 votes1 answer62 viewsQ: Grouping only by Manytomany’s first item in DjangoI have two tables: Author and Book where Book has an Author = ManyToManyField Note the examples with A1 (author one) and L1 (book one), so on. Author - Book A1 - L1, L2, L3 A2 - L1 A1 - L3 A1 - L1… 
- 
		3 votes1 answer276 viewsQ: Total with plurality in Django templateGuys I have the following code: <div> <h4>{{ combination|length }} combinação{{ combination|length|pluralize }}</h4> <h5><b>Total:</b> {{… 
- 
		0 votes1 answer165 viewsQ: Sort Datetimefield by date onlyI wanted to order DateTimeField by date only, ignoring the time. Because in my ordination I need to Person.objects.order_by('-date_joined', 'full_name') But sorting by name has no effect because the… 
- 
		0 votes1 answer744 viewsQ: Using search and pagination field with Function Based View in DjangoI have the following code: #decorators.py from django.contrib.auth.decorators import user_passes_test def superuser_required(func): return user_passes_test( lambda u: u.is_authenticated() and… 
- 
		0 votes2 answers45 viewsQ: Returning manager in template (Django)How do I return the amount of books published in the template? I have it # models.py class PublishedManager(models.Manager): def published(self): return self.filter(published=True) class… 
- 
		2 votes2 answers535 viewsA: Django Custom Template TagsAfter a dialogue, and understanding the real problem we arrived at the following solution: # views.py def from_friday_to_friday(now=datetime.now()): days_from_friday = (now.weekday() - 4) % 7… 
- 
		0 votes1 answer49 viewsA: Error running tests with proxy models in Django"Your Sellermanager returns only sellers and in the test you are creating a manager." Switching to seller solves the problem. 
- 
		3 votes1 answer49 viewsQ: Error running tests with proxy models in DjangoI have a table Seller. https://github.com/rg3915/django-experience/blob/master/djexperience/crm/models.py#L109-L118 class Seller(Employee): objects = SellerManager() class Meta: proxy = True… 
- 
		1 votes1 answer92 viewsQ: Changing the template_name in Templateview (Django)How do I change template_name in Templateview if user is authenticated? Look what I tried class Home(TemplateView): # template_name = 'index.html' is_auth = False def get(self, request): if not… 
- 
		0 votes1 answer56 viewsA: Returning get_status_display in json (Django)from orcamentos.utils.lists import STATUS_LIST p=Proposal.objects.values('status')\ .annotate(value=Count('status'))\ .order_by('status').values('status', 'value') lista=[] for item in p: for choice… djangoanswered Regis Santos 1,574
- 
		0 votes1 answer56 viewsQ: Returning get_status_display in json (Django)I created an issue. https://github.com/rg3915/orcamentos/issues/53 I made a chart using Morris JS https://github.com/rg3915/orcamentos/blob/master/img/graphic.png Question: how do I return… djangoasked Regis Santos 1,574
- 
		2 votes1 answer713 viewsA: Custom Admin DjangoThe documentation https://docs.djangoproject.com/en/1.9/ref/contrib/admin/#admin-Overriding-templates informs that just create the templates/admin/ folder inside the app, in my case myproject/core/… 
- 
		0 votes1 answer713 viewsQ: Custom Admin DjangoI’m trying to change the login screen to a new custom screen, but it’s not working. https://github.com/rg3915/custom-admin I set up the Settings: 'DIRS': [os.path.join(BASE_DIR, 'templates_admin')],… 
- 
		0 votes1 answer121 viewsQ: Problems inserting commands into bashrc via scriptI am trying to insert commands in bashrc via script. I turn the remote source powerpyenv.sh # powerpyenv.sh echo '### Added by pyenv' >> teste echo 'export PATH="$HOME/.pyenv/bin:$PATH"'… 
- 
		0 votes2 answers602 viewsA: Group by Day in DjangoDjango Aggregation, group by day import datetime import itertools qs = Subscription.objects.values('created_at').values('created_at') grouped = itertools.groupby(qs, lambda d:… 
- 
		1 votes2 answers602 viewsQ: Group by Day in DjangoDoes anyone there have an example of a "bat-ready" grouping by date? I tried all this here... Subscription.objects.extra(select={'day':… 
- 
		2 votes0 answers79 viewsQ: Leaving the entire column highlighted (Django + template)I’m trying to leave the whole column colored, but only the last line is getting. I’ve tried every possible logic, but I’m not getting it right. This post is a continuation of Total and subtotal in… 
- 
		4 votes1 answer626 viewsQ: Total and subtotal in Django template using predefined listsHow do I calculate subtotal and total per column? py views. def soma_tuplas(a, b): return (a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3], a[4]) def quotation_list(request): stores =… 
- 
		2 votes1 answer851 viewsQ: Total and subtotal in Django template using listsHow do I calculate the subtotal and total per store (store) in the view to play the results in the template? In this case I’m using lists. def quotation_list(request): stores =… 
- 
		3 votes1 answer155 viewsQ: Returning the minimum value for comparison in Django templateFollowing a reply on /a/96503/761 def quotation_list(request): stores = list(Store.objects.all()) products = list(Product.objects.all()) # indice index_store = {store.id: index for index, store in… 
- 
		2 votes1 answer161 viewsQ: Refactoring Python codeHow do I improve this code? import random import string import requests from django.core.management.base import BaseCommand, CommandError from django.core.exceptions import ValidationError from… 
- 
		4 votes1 answer2809 viewsQ: POST via Ajax with DjangoBased on https://godjango.com/18-basic-ajax/ I am trying to make a post via Ajax using Django. Then I created a project on Github https://github.com/rg3915/front-dj-test #urls.py… 
- 
		3 votes1 answer64 viewsQ: Activating virtualenv in MakefileHow do I activate virtualenv in Makefile? I tried to venv: @virtualenv venv active: @source venv/bin/activate I tried too active: @. venv/bin/activate And nothing.… makefileasked Regis Santos 1,574
- 
		-1 votes1 answer689 viewsA: Reading the json correctly to generate the data for the chart (Ajax and Morris)<script type="text/javascript"> // Lê os dados, que já estão em json var json = function(callback){ var json = null; $.ajax({ url: "http://localhost:8000/uf/", … 
- 
		0 votes1 answer689 viewsQ: Reading the json correctly to generate the data for the chart (Ajax and Morris)https://github.com/rg3915/morris/blob/master/myproject/core/templates/core/persons_by_uf.html#L231-L263 I’m not being able to return the json via ajax, I tried with console.log but it’s returning… 
- 
		0 votes1 answer1008 viewsQ: Treating error when no data is returned (Angularjs)From the question: /a/97757/761 how do I treat the error when it does not find the zip code? See the error that it returns, I wanted you to return an alert when you give this error: XMLHttpRequest… 
- 
		1 votes2 answers2033 viewsA: Returning ZIP Code data in formMy friend @Tony Lamp gave me a little extra help! Thanks @Tony Lamp <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <script… 
- 
		3 votes1 answer533 viewsQ: Setting matrix table in DjangoI have two tables, in the example (any) of the figure below i have the table Paises and the table Energia Setting a third table in Django I would have something with the fields pais, energia, valor… 
- 
		3 votes2 answers403 viewsQ: TDD in existing function (Django)I need to learn more about TDD. What a test it should be to pass? The function already works, just wanted to know what would be a test? @login_required def create_contract(request, proposal_id): if… 
- 
		-1 votes2 answers120 viewsA: Problem with pk that doesn’t exist yetSolved. @login_required def create_contract(request, proposal_id): if request.user.is_authenticated: proposal = Proposal.objects.get(pk=proposal_id) if proposal.status != 'co': return… djangoanswered Regis Santos 1,574
- 
		1 votes2 answers120 viewsQ: Problem with pk that doesn’t exist yetI have the following urls: # urls.py url(r'^proposal/(?P<pk>\d+)/$', ProposalDetail.as_view(), name='proposal_detail'), url(r'^contract/(?P<pk>\d+)/$', ContractDetail.as_view(),… djangoasked Regis Santos 1,574
- 
		3 votes1 answer1550 viewsQ: List date filter (Django)Imagine I have a list and a form to filter this list by date. Does anyone have any example of how to make this filter in the form? I got this here in the shell, but I don’t know how to implement in… 
- 
		1 votes2 answers94 viewsQ: Refactoring generation of random datetime (Python)accept suggestions to improve this code https://github.com/rg3915/django-orm/blob/master/fixtures/gen_random_values.py#L34-L45 import random import datetime def gen_timestamp(min_year=1915,… 
- 
		0 votes1 answer77 viewsQ: Performance in Queryset CBV# models.py class Book(TimeStampedModel): name = models.CharField(_('nome'), max_length=50) authors = models.ManyToManyField('Author', verbose_name='autores') price =… 
- 
		1 votes0 answers34 viewsQ: Creating your own Mixer and Django ProviderI saw that in the mixer there are several providers ready http://fake-factory.readthedocs.org/en/latest/providers.html http://fake-factory.readthedocs.org/en/master/locales/pt_BR.html but there is… 
- 
		4 votes1 answer8275 viewsQ: Modal + form + values (bootstrap and javascript)From the following link http://getbootstrap.com/javascript/#live-demo I created the following modal https://github.com/rg3915/front_end/blob/master/javascript/modal_form.html In the modal I fill a… 
- 
		2 votes3 answers450 viewsA: Annotate: Returning the cheapest product and supplier name (Django)Solved with a different solution (but still accept a better and smaller solution). In the end it was like this from core.models import Quotation from django.db.models import Min… 
- 
		6 votes3 answers450 viewsQ: Annotate: Returning the cheapest product and supplier name (Django)Given the table below product;company;price AAAAA;forn1;395.69 BBBBB;forn1;939.45 CCCCC;forn1;480.33 DDDDD;forn1;590.59 EEEEE;forn1;847.69 AAAAA;forn2;227.31 BBBBB;forn2;375.90 CCCCC;forn2;602.18… 
- 
		1 votes1 answer116 viewsQ: Treating error in search field with text and integer (Django)The following code does a value search in the template. But it locates by text, and when I type, for example, 2015 to locate by year, it returns an error because the field must be an integer and not… 
- 
		3 votes1 answer535 viewsQ: Single CPF but with Blank=TrueIf I define cpf = models.CharField(max_length=11, unique=True, null=True, blank=True) It turns out that if I leave a record with the null value, when I try to save a second record, it accuses… djangoasked Regis Santos 1,574
- 
		2 votes1 answer524 viewsQ: Using json to copy data (Django)I thought better, and I think I’ll use json. def entry_detail_json(request, pk): data = Entry.objects.filter(pk=pk) s = serializers.serialize("json", data) return HttpResponse(s) But being on the…