These are chat archives for django/django

14th
Jun 2017
Anish Shrestha
@annshress
Jun 14 2017 04:12
django.contrib.postgres using Full-Text-Search.
I am getting an issue with SearchVector returning duplicate fields. Can anyone help me???
vector = SearchVector('display_name', weight='A') + SearchVector('city', weight='B') + SearchVector('area', weight='B')
query = SearchQuery(term)

stores_all = Store.objects.annotate(rank=SearchRank(vector, query, weights=RANK_WEIGHTS)).distinct()
Anish Shrestha
@annshress
Jun 14 2017 04:18
But each stores_all has gets multiple result of same instance but with different ranks. Probably each SearchVector is generating a different rank, and hence .distinct() does not return a discting instance.
Any help will be appreciated. Thank you.
penguio
@penguio
Jun 14 2017 04:59
anyone know about django and ajax for interdepedent dropdowns, im having an issue with mine. here's my code
# Filtered Department View #
########################
def ajax_get_department(request):
    if request.POST['company_name'] == "":
        return HttpResponse('<option value=""></option>')
    Company_Name = request.POST['company_name']
    departments = Department.objects.filter(company_name=Company_Name).filter(status="Enabled")
    return render(request,
                  'application_settings/filter_department.html',
{'departments': departments})
<script type="text/javascript">
        function updateDepartment(control){
            var department_sel = $("#{{form.department.auto_id }}").find(':selected').val();
            $.ajax({
                type: 'POST',
                url: (location.href.includes('modify_dept') ? '../../filter_department': 'filter_department'),
            data: {'department': $(control).find(':selected').val() },
            success: function(departmentHTML){
                $('#{{form.department.auto_id }}').html(departmentHTML);
                $('#{{form.department.auto_id }}').val(department_sel);
            }
            });
        }
        $(document).ready(function(){
            $('#{{form.department.auto_id }}').change(function(){
                updateDepartment(this);
            });
            updateDepartment('#{{form.department.auto_id }}');
        });
    </script>
Blake Ridgway
@MaestroShepherd
Jun 14 2017 06:23
Hello, new to Django :)
Shobhit Jain
@Shobhit1610
Jun 14 2017 08:40
I am also a newbie ,can anyone tell me about the resources from where I can study python and django
LuffyKing
@LuffyKing
Jun 14 2017 08:55
Google tdd
I mean obey the testing goat test driven development, django girls( must read ), mdn djandgo and the django official page
Also two scoops of django is more comprehensive but 40 bucks for django 1.11
IS a bit steep
For Python
Automate the boring stuff
Good primer
Shobhit Jain
@Shobhit1610
Jun 14 2017 08:59
Thanks buddy @LuffyKing .Could you also tell me about some video certifications courses.
LuffyKing
@LuffyKing
Jun 14 2017 09:04
Never took them
So I can't help u there
Shobhit Jain
@Shobhit1610
Jun 14 2017 09:06
Nevermind buddy. By the way thanks for your help man
LuffyKing
@LuffyKing
Jun 14 2017 09:06
Happy to help I fully understand your plight!
Shobhit Jain
@Shobhit1610
Jun 14 2017 09:06
Jesús Moreno Amor
@jmorenoamor
Jun 14 2017 10:50
Hi, is it a bad decission to have calculated/cached fields in a model that depends on other related models? Example:
A product that has n components with weights. ¿If I have a calculated field in the product I can know it's weight withouth selecting all the related components
Product weight is updated when any component is modified
Bruno F Souza
@varnion
Jun 14 2017 13:06
@Eskalol without running migrations, the manage.py test raises this: OperationalError: no such table: ceticsdb_project (one of the tables I use in my app)
lots of tests will raise this error
but if I migrate prior to the tests, Everything orks fine
here is the database config
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}
I found really awkward the need to create the db before because the tests are creaing a test database
Bruno F Souza
@varnion
Jun 14 2017 13:12
finally, this is the output on travis if I create the production database before running the tests
coverage run manage.py test ceticsdb
Creating test database for alias 'default'...
......................................
----------------------------------------------------------------------
Ran 38 tests in 38.057s

OK
Roman Tolkachyov
@romantolkachyov
Jun 14 2017 16:25
@varnion looks like you didn't add your app in INSTALLED_APPS (in this case migrations won't applied)
Bruno F Souza
@varnion
Jun 14 2017 17:06
@romantolkachyov it is there
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'dajaxice',
    # 'session_security',
    'mathfilters'
    'ceticsdb',
)
my app is the last one
Bruno F Souza
@varnion
Jun 14 2017 18:26
I followed the trace and finally found the error: a queryset was instantiated inside forms.py
this code has a terrible legacy. sometimes I just want to rewrite everything from zero
anyway, thanks for the attention, @romantolkachyov :smile:
LuffyKing
@LuffyKing
Jun 14 2017 19:02
is it me or should just there be pastebin links when posting code
I find some of it diff to read
Roman Tolkachyov
@romantolkachyov
Jun 14 2017 19:12
@varnion Yeah, full stack trace would be helpful :-)