By CreativeSolutions
Find the last friday using python datetime function
Posted In:
Python
.
By Webdevelopmentlogics
Add pagination in the viewset list function
Posted In:
Djago rest framework
.
By CreativeSolutions
class GenericViewSet(): queryset = ( Contact.objects.select_related("tag") .prefetch_related("employee") .all() ) serializer_class = GenericSerializer http_method_names = ["get"] filterset_class = GenericFilter pagination_class = GenericPagination
def list(self, request):
qs = self.filter_queryset(self.get_queryset())
data = self.paginate_queryset(qs)
serializer = self.get_serializer(qs, many=True)
data = self.get_paginated_response(serializer.data)
return data
Django order by query with value of a column
By Webdevelopmentlogics
django prefetch queryset to get conditional data from existing queryset
By Webdevelopmentlogics
Add nested serializers in custom method function
Posted In:
Djago rest framework
,
Django
.
By Webdevelopmentlogics
class MainSerializer(serializers.ModelSerializer):
deatils= serializers.SerializerMethodField() class Meta: model = Tag fields = ["id", "name", "deatils"] def get_deatils(self, obj): if obj.user_type == "public": return PublicUserSerializer(obj.prefetch_user, many=True).data else: return AdminUserSerializer(obj.prefetch_user, many=True).dataFlutter simple home page with bottom navigation
By Webdevelopmentlogics
// Flutter code sample for BottomNavigationBar
//
// This example shows a [BottomNavigationBar] as it is used within a [Scaffold]
// widget. The [BottomNavigationBar] has four [BottomNavigationBarItem]
// widgets, which means it defaults to [BottomNavigationBarType.shifting], and
// the [currentIndex] is set to index 0. The selected item is amber in color.
// With each [BottomNavigationBarItem] widget, backgroundColor property is
// also defined, which changes the background color of [BottomNavigationBar],
// when that item is selected. The `_onItemTapped` function changes the
// selected item's index and displays a corresponding message in the center of
// the [Scaffold].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// This is the main application widget.
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatefulWidget(),
);
}
}
/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key);
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
class HomepageWidget extends StatelessWidget {
static String routeName = '/';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'App title',
home: Container(
child: Text('Hello World'),
),
);
}
}
/// This is the private State class that goes with MyStatefulWidget.
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
int _selectedIndex = 0;
List _screens = [PageOne(), PageTwo()];
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('BottomNavigationBar Sample'),
),
body: _screens[_selectedIndex],
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
backgroundColor: Colors.red,
),
BottomNavigationBarItem(
icon: Icon(Icons.business),
label: 'Business',
backgroundColor: Colors.green,
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
label: 'School',
backgroundColor: Colors.purple,
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
label: 'Settings',
backgroundColor: Colors.pink,
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
),
);
}
}
class PageOne extends StatelessWidget {
final SnackBar _snackBar = SnackBar(
content: const Text('Message from page one'),
duration: const Duration(seconds: 5),
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.teal,
title: Text('Woolha.com - Page one'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
OutlinedButton(
child: Text('Go to page two'),
onPressed: () {
Navigator.pushNamed(context, '/two');
},
),
OutlinedButton(
child: Text('Show message!'),
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(_snackBar);
},
),
],
),
),
);
}
}
class PageTwo extends StatelessWidget {
final SnackBar _snackBar = SnackBar(
content: const Text('Message from page two'),
duration: const Duration(seconds: 5),
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.teal,
title: Text('Woolha.com - Page Two'),
),
body: Builder(builder: (BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
OutlinedButton(
child: Text('Go to page one'),
onPressed: () {
Navigator.pop(context);
},
),
OutlinedButton(
child: Text('Show message!'),
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(_snackBar);
},
),
],
),
);
}),
);
}
}
Django rest framework select serializer class according the request parameter
By Webdevelopmentlogics
How to install virtualenv with specific python versoin
Posted In:
Python
.
By CreativeSolutions
To use profile model with user form we need to initialize the form fields in the form. Then to get the values on edit we need to initialize __init__ function and passing the profile object from the view
Ex: forms.py
class SuperUserEditForm(forms.ModelForm):
birthday = forms.DateTimeField(input_formats=['%Y-%m-%d %I:%M %p'], required=False)
phone_number = forms.CharField(max_length=100, required=False, label="Home Phone")
cell_number = forms.CharField(max_length=100, required=False)
carrier = forms.ChoiceField(choices=CARRIERS, required=False)
def __init__(self, profile=None, *args, **kwargs):
super(SuperUserEditForm, self).__init__(*args, **kwargs)
if(profile):
self.fields['cell_number'].initial = profile.cell_number
self.fields['carrier'].initial = profile.carrier
self.fields['birthday'].initial = profile.birthday
self.fields['phone_number'].initial = profile.phone_number
Ex: views.py
form = SuperUserEditForm(profile=profile, instance=user)
on POST
form = SuperUserEditForm(data=request.POST, instance=user)
Ex: forms.py
class SuperUserEditForm(forms.ModelForm):
birthday = forms.DateTimeField(input_formats=['%Y-%m-%d %I:%M %p'], required=False)
phone_number = forms.CharField(max_length=100, required=False, label="Home Phone")
cell_number = forms.CharField(max_length=100, required=False)
carrier = forms.ChoiceField(choices=CARRIERS, required=False)
def __init__(self, profile=None, *args, **kwargs):
super(SuperUserEditForm, self).__init__(*args, **kwargs)
if(profile):
self.fields['cell_number'].initial = profile.cell_number
self.fields['carrier'].initial = profile.carrier
self.fields['birthday'].initial = profile.birthday
self.fields['phone_number'].initial = profile.phone_number
Ex: views.py
form = SuperUserEditForm(profile=profile, instance=user)
on POST
form = SuperUserEditForm(data=request.POST, instance=user)
How to remove a category from top menu
Posted In:
Magento 2
.
By CreativeSolutions
How to enable developer mode in magento
Posted In:
Magento 2
.
By CreativeSolutions
To check the current mode, go to the magento installed folder using terminal then use the below command bin/magento deploy:mode:show
[developer@user magento]$ bin/magento deploy:mode:show
Current application mode: default.
To change into developer mode, use the below command
[developer@user magento]$ bin/magento deploy:mode:set developer
Enabled developer mode.
[developer@user magento]$ bin/magento deploy:mode:show
Current application mode: developer.
[developer@user magento]$ bin/magento deploy:mode:show
Current application mode: default.
To change into developer mode, use the below command
[developer@user magento]$ bin/magento deploy:mode:set developer
Enabled developer mode.
[developer@user magento]$ bin/magento deploy:mode:show
Current application mode: developer.
Removing My Wishlist option in Magento
Posted In:
Magento 2
.
By CreativeSolutions
Magengo : how to show product attribute in product listing page
Posted In:
Magento 2
.
By CreativeSolutions
Change all directory permission to 755 and file permission to 644 in linux
By CreativeSolutions
How to clear magento cache in the Server using terminal
Posted In:
Magento 2
.
By CreativeSolutions
How to show django cursor execute query
Posted In:
Django
.
By CreativeSolutions
Using for loop counter in django template
Posted In:
Django
.
By CreativeSolutions
Older Posts
< ||| > > > Newer Posts