SlideShare a Scribd company logo
1 of 35
Download to read offline
MANJE JE VIŠE
ISKORISTITE DJANGO MOGUĆNOSTI KAKO BI PISALI ŠTO
MANJE KODA
Stjepan Zlodi - stjepan at gmail dot com
POSLOVNI PUT
videoteke, kafići (clarion)
1996. Libusoft (clarion)
2000. obrt Lupus (clarion, php)
2001. caatoosee (java, asp, python)
2002. Dimedia (php)
2004. LibusoftCicom (c#, ext.js, alt.net)
2009. Styria (django, ext.js)
2020. > ascalia.io (django)
"SVE VRTI SE U KRUG"
Josipa Lisac
PRODUKTIVNA LIJENOST
Ne ponavljati se, pisati što manje koda.
Programski jezici su samo alati koji vode do rješenja.
10X DEVELOPER
Ne pišu 10x puta više koda.
Ne pišu 10x brže.
Biraju kraći put do rješenja (ali nije uvijek 10x kraći) ;-)
Najbolja rješenja su najednostavnija. Samo je teško naći
put do njih.
TOOL...!...!...!...!...!...!...!...PROBLEM
DVA TIPA DEVELOPERA
ZLATNO VRIJEME ZA DEVELOPERE
Pitanje s ljetnog drinkupa...
Do kada će trajati?
PIŠEMO LI PREVIŠE KODA?
Django model
DRF klase, viewovi, serializatori
JavaScript data klasa
POSLJEDICE?
Razvoj je duži i skuplji, sve više prilika za bugove.
Korisnici traže jeftinija i brža rješenja.
NO-CODE
Što je no-code?
Wordpress
LOW-CODE
Otkrivanje tople vode - nekada RAD
Excel
HOĆE LI NAM DOĆI GLAVE?
Neće!
Uklapanje u postojeća rješenja/aplikacije
Možemo li nešto naučiti od njih?
TREBA LI NAM REBOOT?
Kako da pišemo manje koda i da budemo brži?
Ideje?
Kod koji morfira, koji se mijenja, prilagođava...
SHOW ME THE CODE :-)
Ab ovo
DJANGO DUMP PROBLEM
dumpdata vraća sva polja
- update 8 years ago
Django Dumpdata Field
# app_model=app.Model, fields=field1,field2
Model = apps.get_model(app_model)
fields = fields.split(',')
qs = Model.objects.all()
values = qs.values(*fields)
return json.dumps(values, cls=DjangoJSONEncoder)
1
2
3
4
5
6
7
KAKO UČITATI PODATKE?
Nije komplicirano napisati kod, ali zašto?
Rješenje - dumpati podatke u standardnom Django
dump formatu.
Koristimo već postojeću Django loaddata komandu.
data = dump_structure(app_model, values, fields, Model)
return json.dumps(data, cls=DjangoJSONEncoder)
...
{
	 "model": app_model,
	 "pk": item.get("pk"),
	 "fields": field_values # dict - field:value
}
1
2
3
4
5
6
7
8
9
# order=field2,-field1
order_list = order.split(',')
qs = qs.order_by(*order_list)
1
2
3
4
5
ALI JA HOĆU FILTRIRATI PODATKE
Koji je najbrži i najjednostavniji način?
Django - Field lookups
# filter:created_at__date=2021-10-12,title__icontains=manje
filters = get_filter_dict(options['filter'])
qs = qs.filter(**filters)
...
{'created_at__date':'2021-10-12', 'title__icontains':'manje'}
1
2
3
4
5
6
7
8
9
GDJE JE DATOTEKA?
Path - relativan na media folder root
imgs/nice_slot/ab/image.jpg
Custom storage provider? S3, Azure, Dropbox, Seafile,
FTP, Google Cloud Storage
# hack, ne znam pametnije
# value = 'imgs/nice_slot/ab/image.jpg'
# key - field name
hack = Model()
setattr(hack, key, value)
values[f"{key}__full_url"] = getattr(hack, key).url
1
2
3
4
5
6
7
8
9
DJANGO DUMPDATA ONE
Zašto nema više ovakih malih rješenja otvorenog koda?
https://github.com/ascaliaio/django-dumpdata-one
DINAMIČKI API?
Još koja linija koda...
Manage komandu pretvorimo u View koji vraća JSON
https://moj.local.computer/api/app.model?

	 fields=id,name,title,created_at

	 &order=-created_at

	 &filters=created_at__week_day=3

	 &limit=100
DA LI JE TO UPOTREBLJIVO?
Opasno je!
Django znalci će se snaći, a ostali?
ZAŠTO JE OPASNO?
https://moj.local.computer/api/contenttypes.contenttype
ZA INTERNU SVRHU
Za prijenos podataka između dvije aplikacije -
migracije.
Analitika, statistika.
Dodatno ograničenje pristupa. Hint - možda koristiti
Django permissions?
MOŽE LI SE TO ISKORISTITI I ZA JAVNI API?
Ali bez previše dodatnog koda?
REST API
Ideja - bridge
Graphene Django - dinamička schema
GraphQL
query {

	 posts {

	 	 id

	 	 title

	 	 author {

	 	 	 name
	 	 }
	 }

}
https://moj.local.computer/api/blog.post?

	 fields=id,title,author__name
A ONO MORFIRANJE?
Endpoint koji bi vraćao JavaScript definiciju klase.
NO-CODE, LOW-CODE RJEŠENJE UZ POMOĆ DJANGA?
ZAŠTO NE?
Q&A
ascalia.io
zapošljavamo Django developera s Go sklonostima ;-)
stjepan@ascalia.io
dejan@ascalia.io

More Related Content

Featured

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

Manje je više